Cast and Convert

Tuesday, 9 April 2013

Cast and Convert


1.CAST and CONVERT are two SQL functions used by programmers to convert one data type to another.

2.The CAST function is ANSI standard and is compatible to use in other databases while the CONVERT function is a specific function of the SQL server.

3.Since the CAST function is compatible with other databases, it is also described as portable though it has fewer features compared to the CONVERT function. The CONVERT function, meanwhile, can do some things that the CAST function cannot.

4.The CAST function is used to convert a data type without a specific format. The CONVERT function does converting and formatting data types at the same time.

5.In terms of syntax, both functions have the optional parameter of length. In the CONVERT function, there is an additional parameter called style which specifies the format of the data type after conversion.

6.The CAST function is often used to preserve decimal values and places while converting them into integers. The function can also truncate the decimal value if needed. The CONVERT function cannot perform this task.

No comments:

Post a comment