Home > Net >  Regex in SQL Server, how can i found only certain length of integers
Regex in SQL Server, how can i found only certain length of integers

Time:09-13

I have a table in SQL Server and a column ( consider the column is of varchar or INT data type), The column has values and most of them are integers.

How can I query only integers with length 3, not more than 3 or less than 3 using Regular Expression? is it possible in SQL Server? do I need to install any additional libraries?

Input

column

  1. 123
  2. 234
  3. 4532
  4. 223
  5. 2e34
  6. 234
  7. 22
  8. 23344

Expected Output:

Column

  1. 123
  2. 234
  3. 223
  4. 234

CodePudding user response:

SQL Server does not have Regex. Even if it did, I wouldn't recommend it here

You can just use a cast and BETWEEN

WHERE TRY_CAST(YourColumn AS int) BETWEEN 100 AND 999

If the column is actually an int then you don't even need a cast.

  • Related