ccaring
ccaring

Reputation: 43

SQL Query to search from a string sequence

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

image example

range search 10021-69990 but records like 1002F also appears which is diff category.

Upvotes: 0

Views: 387

Answers (2)

Gordon Linoff
Gordon Linoff

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

Related Questions