Skip to content
Advertisement

Best way to filter data for a given range

I need to find Claims from a given table having a procedure code between the range ‘Q5000’ and ‘Q5090’. I am able to write a function for Int codes but am not sure how to best deal with characters range in SQL Server?

I can manually write all the codes and filter them but is there any way by which I provide the first and Last Value and SQL generates the full set of values.

Select * 
from   dbo.claims 
where  ProcedureCode in ('Q5000',Q5001','Q5002',....,'Q5090')

Advertisement

Answer

This answer in another thread may be helpful for you.

OR

You could also try this assuming same single char is the beginning char.

SELECT * FROM dbo.claims WHERE RIGHT(ProcedureCode, LEN(ProcedureCode)-1) BETWEEN 5000 AND 5090

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement