Search This Blog

Friday, June 13, 2014

Format SQL Server Example

SQL Server > Built-in Functions > FORMAT

Formats a values to specific format.






Example:

A.
DECLARE @d DATETIME = '10/17/2014';
SELECT FORMAT ( @d, 'd', 'en-US' ) AS 'US English Result'
      ,FORMAT ( @d, 'd', 'de-de' ) AS 'German Result'

      ,FORMAT ( @d, 'd', 'ro-ro' ) AS 'Romanian Result';

Result

US English Result German Result Romanian Result
10/17/2014         17.10.2014 17.10.2014

B.
DECLARE @d DATETIME = GETDATE();
SELECT FORMAT( @d, 'dd/MM/yyyy')

Result
(No column name)
13/06/2014

C.
SELECT FORMAT(100, 'N', 'en-us') AS 'Number Format',FORMAT(200, 'C', 'en-us') AS 'Currency Format'

Result
Number Format Currency Format
100.00         $200.00