Friday, 20 May 2016

CAST & CONVERT function in SQL server ?

To convert from one datatype to another we can use cast and convert function in SQL server.

SYNTAX

CAST (EXPRESSION AS DATATYPE[LENGTH])

EXAMPLE





SYNTAX

CONVERT (DATATYPE[LENGTH],EXPRESSION,[STYLE])

EXAMPLE







you can use the various style format (such as 101,120,103) in convert function to get different types of date formats as shown below.



You can refer the below screenshot to get idea about possible conversion within the SQL data types.


No comments:

Post a Comment