Tuesday, October 11, 2016

cast and convert

SQL cast and convert provides same functionality .They use to convert one data type to another.

cast()

cast() used for to convert one data type to another data type. 

Query :

DECLARE @BA varchar(20)
DECLARE @CA varchar(20)
set @BA=100
set @CA=3
Select CAST(@BA as int) +CAST (@CA as int) as Result


Result:







convert()

Convert used for convert date or time to display various format.

Query :
DECLARE @DEL char(30)
SELECT @DEL=current_timestamp
select CAST (@DEL as date) as CurrentDate

Result:


No comments:

Post a Comment