现有表A结构:
id custname protype
1 常州银河 2CW035*YQ
2 常州银河 2CW035*YQ-PX
3 东莞中之 2CW028*YQ
4 东莞中之 2CW032*YQ-PX现在我 只能获得custname 和 一个具体的protype 如
常州银河,2CW035222YQ-PX
我如何通过sql能得到记录2的结果select * FROM a WHERE custname='常州银河' and left(protype,CHARINDEX('*', protype)-1) in ('2CW035222YQ-PX') and
right(protype,len(protype)-CHARINDEX('*', protype)) in ('2CW035222YQ-PX')
这样写得不到
id custname protype
1 常州银河 2CW035*YQ
2 常州银河 2CW035*YQ-PX
3 东莞中之 2CW028*YQ
4 东莞中之 2CW032*YQ-PX现在我 只能获得custname 和 一个具体的protype 如
常州银河,2CW035222YQ-PX
我如何通过sql能得到记录2的结果select * FROM a WHERE custname='常州银河' and left(protype,CHARINDEX('*', protype)-1) in ('2CW035222YQ-PX') and
right(protype,len(protype)-CHARINDEX('*', protype)) in ('2CW035222YQ-PX')
这样写得不到
而且我也不知道2CW035222YQ-PX 从什么地方*号开始分割一开始我也是简单的以为LIKE但是发现不对,like 左右是什么呢?
select * FROM a WHERE custname='常州银河' and REPLACE(myname,'*','22') = '2CW03522YQ-PX'
select * FROM a WHERE custname like '%常州银河%' and protype like '2CW035%YQ-PX'
的结果 ???
现有表A结构:
id custname protype beipin
1 常州银河 2CW035*YQ 0.02
2 常州银河 2CW035*YQ-PX 0.01
3 东莞中之 2CW028*YQ 0.03
4 东莞中之 2CW032*YQ-PX 0.04现在我 只能获得custname 和 一个具体的protype 如
常州银河,2CW035222YQ-PX (protype 我是不知道*号从什么地方分割的,他只是记录的一个规则)
而我最终的目的是通过客户名和protype的实际值去数据库中匹配,得到beipin,现在的关键问题是
我怎样才能在数据库中找到protype和2CW035222YQ-PX 匹配的记录.
select beipin FROM a WHERE custname='常州银河' and left(protype,CHARINDEX('*', protype)-1) in ('2CW035222YQ-PX') and
right(protype,len(protype)-CHARINDEX('*', protype)) in ('2CW035222YQ-PX')
这样写得不到
select * FROM a WHERE custname like '%常州银河%' and protype like '2CW035%YQ-PX'
如 我得到的是2CW035222YQ-PX 他应该和2CW035*YQ-PX 匹配
而要是得到的是2CW035111YQ 则他应该和2CW035*YQ 匹配,
and right(myname,len(myname)-len(left(myname,CHARINDEX('*', myname)))) = right('2CW035222YQ-PX',len(right(myname,len(myname)-len(left(myname,CHARINDEX('*', myname)))))) 这样是拆出来的。myname改成protype ,'2CW035222YQ-PX'换成你取回来的变量值。再加上你的custname like '%常州银河%'