Wednesday, July 20, 2011

SQL Server Denali Feature Watch - FORMAT(), as in, "OMG we finally get .Net like Number/Date/Time formatting in our TSQL" Or "Saying goodbye to my old friend, Convert(103)..."

Sql&Me - SQL Server – "Denali" – String Formatting using FORMAT()

"SQL Server "Denali" introduces a new function FORMAT() for formatting of DATETIME and numeric values. In Earlier versions we did date and time conversions using CAST and CONVERT as below:

DECLARE @d DATETIME = GETDATE()

SELECT CONVERT(VARCHAR, @d, 103) AS 'dd/MM/yyyy',
CONVERT(VARCHAR, @d, 104) AS 'dd.MM.yyyy',

...

FORMAT() uses .NET Framework format string. It can be used as below:

DECLARE @d DATETIME = GETDATE()

SELECT FORMAT ( @d, 'dd/MM/yyyy') AS 'dd/MM/yyyy',
FORMAT ( @d, 'dd.MM.yyy') AS 'dd.MM.yy',
FORMAT ( @d, 'dd/MMM/yyy') AS 'dd/MMM/yy',
FORMAT ( @d, 'MMM dd, yy') AS 'MMM dd, yy'

...

image ..."

For some, this feature alone might be worth upgrading. I mean, ZOMG, "real" Date/Time/Number formatting! And best of all, it's the CLR based formatting style too.

For more information, here's the current doc's, http://msdn.microsoft.com/en-us/library/hh213505(v=SQL.110).aspx

(via SQLServerPedia - SQL Server – "Denali" – String Formatting using FORMAT())

 

Related Past Post XRef:
SQL Server Denali FileTables Feature - The fruits of WinFS? (Think "A FileStream enabled table that you can access as a network file share and other standard File IO API's" or "SQL Server File System in a Table")
Denali CTP3 introduces LocalDB - Think SQL Server Express crossed with SQL CE (or SQL CE grown up or SQL Express made as almost as easy CE)
SQL Server Denali Sequence Object Overview
A couple SQL Server ColumnStore references...
Time to start thinking about, and providing feedback on, what you’ll need to upgrade to Denali (aka next version of SQL Server)

No comments:

Post a Comment

NOTE: Anonymous Commenting has been turned off for a while... The comment spammers are just killing me...

ALL comments are moderated. I will review every comment before it will appear on the blog.

Your comment WILL NOT APPEAR UNTIL I approve it. This may take some hours...

I reserve, and will use, the right to not approve ANY comment for ANY reason. I will not usually, but if it's off topic, spam (or even close to spam-like), inflammatory, mean, etc, etc, well... then...

Please see my comment policy for more information if you are interested.

Thanks,
Greg

PS. I am proactively moderating comments. Your comment WILL NOT APPEAR UNTIL I approve it. This may take some hours...