datetime tune date into pad dynamic cursor money percent sp job isnumeric while over update
FREE TRIAL  SQL 2012 PROGRAMMING  SEARCH
SQL Server Scripts SQL 2005 SQL 2008 Articles
SQL JOBS NEWS FORMAT DEV JOBS
How to use the FORMAT function?

The following Microsoft SQL Server T-SQL sample script demonstrates the the usage of the FORMAT function which is new to SQL Server 2012:

-- US currency formatting

SELECT FORMAT(7771.22,'c','en-us');

-- $1,777.22

 

-- UK currency formatting

SELECT FORMAT(7771.22,'c','en-gb');

-- £1,777.22

 

-- Datetime formatting for US culture

SELECT FORMAT( getdate(), 'yyyy/MM/dd hh:mm:ss tt', 'en-US' ) -- 2016/06/03 09:56:44 AM

SELECT FORMAT( getdate(), 'MMM dd, yyyy hh:mm:ss tt','en-US') -- Jun 03, 2016 09:57:45 AM

 

-- Date formatting

SELECT FORMAT ( getdate(),'y')   -- July, 2016

SELECT FORMAT ( getdate(),'M')   -- July 17

SELECT FORMAT ( getdate(),'d')   -- 7/17/2016

 

-- Percent formatting

SELECT      ProductNumber,

            ListPrice = FORMAT(ListPrice, 'c', 'en-US'),

            Markup = FORMAT(ListPrice / StandardCost, 'p','en-us')

FROM AdventureWorks2012.Production.Product

WHERE ListPrice > 0.0

/*    ProductNumber           ListPrice         Markup

      SA-M198                 $133.34           135.00 %

      SA-M237                 $147.14           135.00 %

      SA-M687                 $196.92           134.99 %

      SA-R127                 $133.34           135.00 %

      SA-R430                 $147.14           135.00 %

      SA-R522                 $196.92           134.99 %  ....*/

 

------------

 

Related articles:

FORMAT (Transact-SQL)

 

Exam Prep 70-461
Exam 70-461