Cast() and Convert() Functions in SQL Server
Cast() Function The Cast() function is used to convert a data type variable or data from one data type to another data type. The Cast() function provides a data type to a dynamic parameter (?) or a NULL value. Syntax CAST ( [Expression] AS Datatype) The data type to which you are casting an expression is the target type. The data type of the expression from which you are casting is the source type. Example DECLARE @A varchar ( 2 ) DECLARE @B varchar ( 2 ) DECLARE @C varchar ( 2 ) set @A = 25 set @B = 15 set @C = 33 Select CAST ( @A as int ) + CAST ( @B as int ) + CAST ( @C as int ) as Result OUTPUT Example DECLARE @Z char ( 30 ) SELECT @Z = current_timestamp select CAST ( @Z as date ) as result OUTPUT Convert() Function When you...