Using CLR under the covers, we will now finally have relative parity with the .format() function we are used to using in .NET languages like C#. This means we needn’t to memorize codes like 101 and 103 anymore (to convert datetime values to localized presentation formats), or we can easily format the currency values etc.
Examples: Format date with Format Function as:
DECLARE @d DATE = '2012-11-19';
SELECT FORMAT(@d, N'yyyy-MM'),
FORMAT(@d, N'yyyy-MM-dd'),
FORMAT(@d, N'yyyy-MMM'),
FORMAT(@d, N'dddd, MMM dd, yyyy'),
FORMAT(@d, N'dddd, MMMM dd, yyyy')
|
And the result is:
Format currency values as:
DECLARE @m DECIMAL(12,2) = 322311.43;
-- 'en-us' is culuture.
SELECT Display = FORMAT(@m, 'C', 'en-us')
|
And here is result:
Comments
Post a Comment