conversion
-
how to convert a string to integer of length 4?which function to use? P.PaVaN KuMaR
-
how to convert a string to integer of length 4?which function to use? P.PaVaN KuMaR
select convert(int,ColumnName) from TableName
orselect cast(ColumnName as int) from TableName
---------- Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peters -
select convert(int,ColumnName) from TableName
orselect cast(ColumnName as int) from TableName
---------- Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. PetersI would suggest to add the
isnumeric
function if you are not absolutely sure that the string ALWAYS contains valid ints:select cast( case when isnumeric(ColumnName)=1 then ColumnName else NULL end as int ) from TableName
Regards, Rainer. Rainer Stropek Visit my blog at http://www.cubido.at/rainers
-
I would suggest to add the
isnumeric
function if you are not absolutely sure that the string ALWAYS contains valid ints:select cast( case when isnumeric(ColumnName)=1 then ColumnName else NULL end as int ) from TableName
Regards, Rainer. Rainer Stropek Visit my blog at http://www.cubido.at/rainers
r.stropek wrote:
select cast( case when isnumeric(ColumnName)=1 then ColumnName else NULL end as int ) from TableName
Makes sense. Thanks. ---------- Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peters