Reputation: 43
Records in database are as:
Code Description
10021 ABC
10023 ABC
.... ....
10100 ABC
9000A XYZ
9001B XYZ
..... ....
9026Z XYZ
Now i have to search sequence like code from 10021-10100 or from 9000A-9026Z these are varchar values. How can I query to get respective ranges of codes
range search 10021-69990 but records like 1002F also appears which is diff category.
Upvotes: 0
Views: 387
Reputation: 591
You can use the STUFF() fonction ! Please see the link :https://social.msdn.microsoft.com/Forums/biztalk/en-US/d53f6285-5fb8-4656-b3ff-e28aa47d3e90/listagg-function-in-sql-server?forum=databasedesign
Hope that can help.
Upvotes: 0
Reputation: 1269603
You would use comparisons:
select *
from t
where code >= '10021' and code <= '10100';
The comparison values need to be strings. Are you aware that these work on string values? The ordering is based on the collation of the strings -- but that is happily usually just alphabetic ordering.
Upvotes: 1