我想比较sql server数据库中的字母数字值并选择特定范围内的值。
例如:员工等级在A1到A20的范围内,我想选择所有大于A5等级的员工。
EMP_ID GRADE 1111 A01 2222 A15 3333 A09 4444 A09 5555 UC 6666 A14 7777 A15 8888 TRN 9999 A04 4242 A14 1212 TRN 1515 A12 5541 UC 5563 A05 These are sample values. When I run the select query without using predicate "AND LEFT(GRADE,1) = 'A' ", it is only retrieving values up to A6, where as it should retrieve up to A15 which is maximum in current scenario. Where as after using the predicate "AND LEFT(GRADE,1) = 'A' " I am getting correct values i.e. up to A15 in this same scenario. GRADE column can have any number of repeated entries. All of them needs to be retrieved. Can you please tell best possible to do this without using predicate "AND LEFT(GRADE,1) = 'A' "?
答案 0 :(得分:0)
您可以提取整数部分并将其用作过滤器:
SELECT * FROM TBL_NAME
WHERE CAST(SUBSTRING(GRADE,2,LEN(GRADE)-1) AS INT) > 5