How is the cast function used in sql server?

In SQL Server, the CAST function is used to convert an expression to a specified data type. The basic syntax is as follows:

CAST ( expression AS data_type )

In this case, the expression is the expression to be converted, and data_type is the data type to be converted to. For example, converting a string to an integer type:

SELECT CAST('123' AS int)

Expressions can be converted to the following data types using the CAST function: binary, char, date, datetime, decimal, float, int, money, nchar, numeric, nvarchar, real, uniqueidentifier, varbinary, varchar, etc.

Leave a Reply 0

Your email address will not be published. Required fields are marked *


广告
Closing in 10 seconds
bannerAds