如:数据库中字段【A值范围】的数据格式为:”30<A<=90“,
标签号 A值范围
A001 30<=A<90
A002 30<=A<90
A003 0<=A<30
A004 0<=A<30
而现在的A值为45,怎么通过sql语句查询出对应的记录?
------解决思路----------------------
select parsename('192.168.12.8',1)
select parsename('192.168.12.8',2)
select parsename('192.168.12.8',3)
select parsename('192.168.12.8',4)
8
(1 行受影响)
--------------------------------------------------------------------------------------------------------------------------------
12
(1 行受影响)
--------------------------------------------------------------------------------------------------------------------------------
168
(1 行受影响)
--------------------------------------------------------------------------------------------------------------------------------
192
(1 行受影响)
后面怎么处理你懂的
select parsename(replace(replace('30<=A<90','<','.'),'>','.'),1)
select parsename(replace(replace('30<=A<90','<','.'),'>','.'),3)
------解决思路----------------------
无非就是将30<=A<90改写成sql条件:
string s = "30<=A<90";
string symbol1 = Regex.Match(s, @"(?<=\d+)[\<\>\=]+").Value;
string symbol = "";
string symbol2 = Regex.Match(s, @"[\<\>\=]+(?=\d+)").Value;
if (symbol1.Contains("<")) symbol = symbol1.Replace("<", ">");
if (symbol1.Contains(">")) symbol = symbol1.Replace(">", "<");
symbol1 = symbol;
sql = " where A" + symbol1 + Regex.Match(s, @"^\d+").Value + " and A" + symbol2 + Regex.Match(s, @"\d+$").Value;