0% found this document useful (0 votes)
9 views

Convert Int Varchar Date

The document describes how to use the CONVERT and CAST functions in SQL to change the data type of values between VARCHAR, INT, and DATE data types. It provides examples of converting between each data type.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Convert Int Varchar Date

The document describes how to use the CONVERT and CAST functions in SQL to change the data type of values between VARCHAR, INT, and DATE data types. It provides examples of converting between each data type.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

 Syntax Convert(datatype , data)

- syntax Cast(data as datatype)

--cONVERT VARCHAR TO INT


SELECT convert(NUMERIC(5,2),'123')
select CAST('123' as int)
--select CAST('123A' AS INT) THROWS ERROR

----CONVERT INT TO VARCHAR


SELECT CONVERT(VARCHAR(4),123)
SELECT CAST(123 AS VARCHAR(4))

----CONVERT DATE TO VARCHAR


SELECT CONVERT(VARCHAR(19),GETDATE())
SELECT CONVERT(VARCHAR(10),GETDATE(),110)
SELECT CONVERT(VARCHAR(24),GETDATE(),113)

--CONVERT VARCHAR to date


SELECT CONVERT(DATETIME,'20110915')

You might also like