With the anticipation of the arrival of the new version of Microsoft SQL Server coming out in 2012…Microsoft asks, which new features of SQL Server 2012 are you most excited about?

Although there are tons of new features that improve security, availability, business intelligence, and integration with other Microsoft applications, the feature I am most excited about is improved formatting with the introduction of a new T-SQL function called FORMAT(). Formatting dates and currencies can be done in current version of SQL, but not very easily. You can attempt formatting using SQL Server’s STR(), CAST(), and CONVERT() functions, but they often produce undesired results and complex queries.

I started out as a Microsoft SQL Server girl, but was then hired by a company that programmed in PHP with a MySQL database. After leaving that job and getting hired on by a Microsoft partner, eimagine, I was back to using SQL Server again. The one thing that I missed most about leaving MySQL was the ability to easily format dates and times; with Microsoft SQL Server formatting dates became frustrating. I missed how easy it was to format dates like I was able to with MySQL.

Finally Microsoft seems to have caught on to developers’ frustrations, and decided to improve formatting in the SQL Server 2012! We will now be able to format dates, times, and currencies easily with the FORMAT() function.

The FORMAT() function will accept 3 values: value, format, and culture (optional): FORMAT(value, format [,culture])

Date formatting Examples:

Code Result
SELECT FORMAT(‘2012-01-02’, N’MM-dd-yyyy’) 01-02-2012
SELECT FORMAT(‘2012-01-02’, N’dddd, MMM dd, yyyy’) Monday, Jan 02, 2012
SELECT FORMAT(‘2012-01-02’, N’dddd, MMMM dd, yyyy’, N’fr-fr’) Lundi, janvier 02, 2012

Currency Formatting Examples:

Code Result
SELECT FORMAT(150456.25, N’C’, N’en-us’) $150,456.25
SELECT FORMAT(150456.25, N’C’, N’fr-fr’) 150 456,25
SELECT FORMAT(150456.25,
N’C’, N’en-gb’)

This T-SQL FORMAT() function is the feature I am most excited about with the upcoming release of Microsoft SQL Server 2012. What is yours?

Like this post? Share it!