Wednesday, October 10, 2012

How to convert the Date/Number to string in sql server 2012

The new version(2012) of sql server makes easy to string conversion from number or date.We don't have any direct  function to do this one in older versions .If we want to do this one ,then we have to use Conversion functions(CAST or CONVERT).
SELECT CAST(date AS nvarchar(100)) AS string_date from Orders
The FORMAT string function has introduced to convert the number/date to string in Sql server 2012 .Here i have given a simple query to get the amount(It has money data type in table)  in currency format.
SELECT order_ID,FORMAT(Price_Amt, 'C', 'en-us') AS 'Amount' from Orders
In this function we  have to use standard numeric formats for desired Format ..Details about standard Numeric Format Strings

2 comments:

ASP.Net Migration said...

Great information about converting number to string in sql server.

Bhaskara said...

Thanks for your valueble comments

Bel