CAST/CONVERT Functions

CAST/CONVERT Functions

Explicitly converts an expression of one data type to another. CAST and CONVERT provide similar functionality.

Syntax

CAST ( expression AS data_type )

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

Arguments
expression

Is any valid expression.

data_type

Is the target system-supplied data type.

length

Is an optional parameter of nchar, nvarchar, char, varchar, binary, or varbinary data types.

style

Is an optional string parameter that allows predefined or user-defined formatting of the data type.  Style must be compatible with styles supported by the Visual Basic .NET Format function.

Examples


SELECT CAST(seller_rating as int) FROM [seller_info]

 SELECT CONVERT(int, seller_rating) FROM [seller_info]