I have a table with these two columns:
transaction_code, transaction_description
I need to have a way of selecting a RANGE of transaction codes from from this table. So for example, you would input 'A' as the starting code and 'D' as the ending code to get all the 'A','B','C','D' records. So naturally I would write something like this:
select transaction_code, transaction_description from tran_table where transaction_code BETWEEN @tran1 and @tran2
However there is a catch. There are also transaction codes which are numeric (i.e. 1,2,3,5...9). Not only that, but numeric codes come AFTER the alphabetic ones. Therefore, in some cases I could have 'X' as the beggining code and '3' as the ending code. Which is suppose to return 'X','Y','Z','1','2','3'. Obviously, the statement -
select transaction_code, transaction_description from tran_table where transaction_code BETWEEN 'X' and '3'
- will not work, because 'X' is greater then '3' and the range is invalid.
There is no way around this, and I also cannot use two ranges (ie X-Z and 1-3) for reasons too long to explain. Does anyone have any ideas?
Thanks!
transaction_code, transaction_description
I need to have a way of selecting a RANGE of transaction codes from from this table. So for example, you would input 'A' as the starting code and 'D' as the ending code to get all the 'A','B','C','D' records. So naturally I would write something like this:
select transaction_code, transaction_description from tran_table where transaction_code BETWEEN @tran1 and @tran2
However there is a catch. There are also transaction codes which are numeric (i.e. 1,2,3,5...9). Not only that, but numeric codes come AFTER the alphabetic ones. Therefore, in some cases I could have 'X' as the beggining code and '3' as the ending code. Which is suppose to return 'X','Y','Z','1','2','3'. Obviously, the statement -
select transaction_code, transaction_description from tran_table where transaction_code BETWEEN 'X' and '3'
- will not work, because 'X' is greater then '3' and the range is invalid.
There is no way around this, and I also cannot use two ranges (ie X-Z and 1-3) for reasons too long to explain. Does anyone have any ideas?
Thanks!