SQL FORMAT () Fonction
La fonction Format ()
La fonction FORMAT () est utilisé pour formater comment un champ doit être affiché.
FORMAT SQL () Syntaxe
SELECT FORMAT(column_name,format) FROM table_name
| Paramètre | Description |
|---|---|
| column_name | Nécessaire. Le champ doit être formaté. |
| format | Nécessaire. Spécifie le format. |
FORMAT SQL () Exemple
Nous avons ce qui suit table "Produits":
| Prod_id | ProductName | Unité | UnitPrice |
|---|---|---|---|
| 1 | Jarlsberg | 1000 g | 10,45 |
| 2 | Mascarpone | 1000 g | 32,56 |
| 3 | Gorgonzola | 1000 g | 15,67 |
Maintenant, nous voulons afficher les produits et les prix par date d'aujourd'hui (avec la date du jour s'affiche dans le format suivant: "AAAA-MM-JJ").
On utilise l'instruction SELECT suivante:
SELECT ProductName, UnitPrice, FORMAT(Now(),'YYYY-MM-DD') as PerDate
FROM Products
FROM Products
L'ensemble de résultats se présente comme suit:
| ProductName | UnitPrice | PerDate |
|---|---|---|
| Jarlsberg | 10,45 | 07/10/2008 |
| Mascarpone | 32,56 | 07/10/2008 |
| Gorgonzola | 15,67 | 07/10/2008 |

0 commentaires:
Post a Comment
HELLO VISITORS THANKS FOR YOUR VISIT AND COMMENT