2015. 6. 20. 23:45

http://www.w3schools.com/sql/sql_func_format.asp


The FORMAT() Function

The FORMAT() function is used to format how a field is to be displayed.

SQL FORMAT() Syntax

SELECT FORMAT(column_name,format) FROM table_name;
ParameterDescription
column_nameRequired. The field to be formatted.
formatRequired. Specifies the format.

Demo Database

In this tutorial we will use the well-known Northwind sample database.

Below is a selection from the "Products" table:

ProductIDProductNameSupplierIDCategoryIDUnitPrice
1Chais1110 boxes x 20 bags18
2Chang1124 - 12 oz bottles19
3Aniseed Syrup1212 - 550 ml bottles10
4Chef Anton's Cajun Seasoning2248 - 6 oz jars21.35
5Chef Anton's Gumbo Mix2236 boxes25

SQL FORMAT() Example

The following SQL statement selects the product name, and price for today (formatted like YYYY-MM-DD) from the "Products" table:

Example

SELECT ProductName, Price, FORMAT(Now(),'YYYY-MM-DD') AS PerDate
FROM Products;

Try it yourself »


'SQL' 카테고리의 다른 글

Hosting  (0) 2015.06.20
Quick Reference From W3Schools  (0) 2015.06.20
NOW() Function  (0) 2015.06.20
ROUND() Function  (0) 2015.06.20
LEN() Function  (0) 2015.06.20
Posted by Name_null