Sunday, 15 July 2012

casting - T-SQL find only the columns which can be casted as INT -


I have to write a SELECT statement, which has a WHERE block, where only I

is it possible

I am on a SQL server **

I am doing something like this:

/ p>

  column Cast (INT) Where the table ISNUMERIC (column) = 1  

but then I have lots of different data conversion 275,949,275,947 'varchar value' column - But I only need INTs

A Kyuel Server 2012:

  select try_parse (select "+1231321313" As Integer) try_parse ( '234242342341231321' as integer)  

SQL Server & lt; 2012:

  select case when ISNUMERIC ( '+1231321313') = 1 and PATINDEX ( '% [^ 0-9 -]%', '+1231321313') = 0 and artists ( the "+1231321313 '-2147483648 and 2147483647 cast among bigint) aS (" +1231321313 "in -2147483648 and 2147483647 as select case integer) end when ISNUMERIC (' 234242342341231321 ') = 1 and bigint between cast ( '234242342341231321') so as to cast ( '234242342341231321' integer) end  

edit: potential currency values ​​( '$ +23424231321', '€ +234 4231321 "etc.) to deal with, you can also add PATINDEX ( '% [^ 0-9-]%', '1231321313') = 0


No comments:

Post a Comment