Friday, November 9, 2007

Convert Function in SQL

The convert function is used to convert datatype into another in a particular pattern.
The syntax of convert is as follows :

CONVERT ( data_type [ ( length ) ] , expression [ , style ] )

The datatype is a system supplied data type to which the expression is being converted.

The expression is any valid expression

The length
is an optional parameter of nchar, nvarchar, char, varchar, binary, or varbinary data types.

And the style is the style of date format used to convert datetime or smalldatetime data to character data (nchar, nvarchar, char, varchar, nchar, or nvarchar data types), or the string format when converting float, real, money, or smallmoney data to character data (nchar, nvarchar, char, varchar, nchar, or nvarchar data types). Also Refer

Note : If you use the CONVERT function to convert a value to a variable length datatype, such as VARCHAR, always specify the length of the variable datatype. If you do not, SQL Server assumes a default length of 30. Ideally, you should specify the shortest length to accomplish the required task. This helps to reduce memory use and SQL Server resources.

Example...

Reference ..

1 comment:

Anonymous said...

Who knows where to download XRumer 5.0 Palladium?
Help, please. All recommend this program to effectively advertise on the Internet, this is the best program!