Char to int

  • "Do not attempt to construct, for example, binary values and convert them to a data type of the numeric data type category. SQL Server does not guarantee that the result of a decimal or numeric data type conversion to binary will be the same between releases of SQL Server." - BOL Convert

    How do I find values over 7000 in a char column with values like '2AA' or '45B' or '5000BM'

    There are allways a number first and then one or two letters.

    Regards Joejoe

     

  • declare @a varchar(20)

    select @a = '122aa'

    select CONVERT( INT, SUBSTRING( @a, 1, patindex( '%[A-Z]%', @a ) - 1 ) )

    Filter the statement with WHERE col LIKE '[0-9]%' so that it only affects rows that begin with number.

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply