[tutorial] SQL format() function



Format() function

The format() function is used to format the display of fields.

SQL format() syntax

SELECT FORMAT(column_name,format) FROM table_name;

Parameter description

column_ Name is required. The field to format.

Format is required. Specify the format.

Demo database

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

Here is the data selected from the products table:

ProductID    ProductName                SupplierID    CategoryID    Unit                Price

1                    Chais                            1                1            10 boxes x 20 bags18

2                    Chang                            1                        1                    24 – 12 oz bottles19

3                    Aniseed Syrup                1                2                        12 – 550 ml bottles10

4                    Chef Anton’s Cajun Seasoning            2            2                        48 – 6 oz jars21.35

5                    Chef Anton’s Gumbo Mix                2                2                36 boxes25

SQL format() instance

The following SQL statement selects the product name and the price of the day (formatted as yyyy-mm-dd) from the “products” table:


SELECT ProductName, Price, FORMAT(Now(),’YYYY-MM-DD’) AS PerDate

FROM Products;

In addition, if you want to better improve your programming ability, learn C language c + + programming! Overtaking on the curve, one step faster! I may be able to help you here~

Up has uploaded some video tutorials for learning C / C + + programming on its home page. Those who are interested or learning must have a look! It will help you~

Share (source code, project video, project notes, basic introductory course)

Welcome to change and learn programming partners, use more information to learn and grow faster than their own thinking Oh!

Free learning books:


Free learning materials: