Convert a literal:
Cast('0001' As Int)
Convert(Int, '0001')
Convert a variable:
Declare @var varchar(8)
Set @var='2399'
Cast(@var As Int)
Convert(Int, @var)
Convert a column:
Cast(varcharCol As Int)
Convert(Int, varcharCol)
If you can't get these to work, please post your SQL code, a sample of the source data and the output of the SQL statment including error or warning messages. Terry L. Broadbent - DBA
Computing Links:
faq183-874 contains "Suggestions for Getting Quick and Appropriate Answers" to your questions in the SQL Server forum. Many of the ideas apply to all forums.
SQL will implicitly make some conversions if possible. However, when selecting the columns in a query you must explicitly convert them to the desired data type. Terry L. Broadbent - DBA
Computing Links:
faq183-874 contains "Suggestions for Getting Quick and Appropriate Answers" to your questions in the SQL Server forum. Many of the ideas apply to all forums.
Cast and Convert don't change the data type of the variable, column or literal. The data type of the output is whatever you've declared it to be.
I'm not sure what you mean by "I thought you had to set to keep the new value on:".
Cast(@var As Int),
Convert(Int, @var) Terry L. Broadbent - DBA
Computing Links:
faq183-874 contains "Suggestions for Getting Quick and Appropriate Answers" to your questions in the SQL Server forum. Many of the ideas apply to all forums.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.