SQL FORMAT () function

FORMAT () function

FORMAT function is used to display format field.

SQL FORMAT () syntax

	SELECT FORMAT(column_name,format) FROM table_name
parameter description
column_name essential. To format the field.
format essential. Prescribed format.

SQL FORMAT () example

We have the following "Products" table:

Prod_Id ProductName Unit UnitPrice
1 gold 1000 g 32.35
2 silver 1000 g 11.56
3 copper 1000 g 6.85

Now we want to show every day corresponding to the date of the name and price (the display format of the date is "YYYY-MM-DD").

We use the following SQL statement:

	SELECT ProductName, UnitPrice, FORMAT(Now(),'YYYY-MM-DD') as PerDate
FROM Products

The result set will look like this:

ProductName UnitPrice PerDate
gold 32.35 12/29/2008
silver 11.56 12/29/2008
copper 6.85 12/29/2008

Guess you like

Origin www.cnblogs.com/sysoft/p/11595838.html