SQL-W3School- function: SQL FORMAT () function

ylbtech-SQL-W3School- function: SQL FORMAT () function

 

1. Back to top
1、

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
2、
2. Return to top
 
3. Back to top
 
4. Top
 
5. Top
1、
2、
 
6. Back to top
 
warn Author: ylbtech
Source: http://ylbtech.cnblogs.com/
This article belongs to the author and blog Park total, welcome to reprint, but without the author's consent declared by this section must be retained, and given the original connection in the apparent position of the article page, otherwise reserves the right to pursue legal responsibilities.

Guess you like

Origin www.cnblogs.com/storebook/p/11827921.html