当前位置:编程学习 > C#/ASP.NET >>

sqlserver查询的问题

假如表1:
col001
aa
bb
cc
dd

表2:
col001 col002
dfdaa       bb
ccdd       dd
weddqwe       er
gffg     sdfwe

问一下,怎么用表2的col001去模糊匹配表1的col001
我这样写不行
select * from 表1 a join 表2 b on a.col001 like %b.col001%
报错了...求正解..
--------------------编程问答-------------------- 没看明白楼主的意思,把你要的结果贴出来 --------------------编程问答--------------------
select * from 表1 A join 表2 B on patindex('%'+A.col001+'%',B.col001)>0
--or
select * from 表1 A,表2 B where patindex('%'+A.col001+'%',B.col001)>0
--or
select * from 表1 A,表2 B where B.col001 like '%'+A.col001+'%'
--------------------编程问答-------------------- 2楼正解,顶一下先! --------------------编程问答-------------------- select * from 表1 A,表2 B where B.col001 like '%'+A.col001+'%'
--------------------编程问答-------------------- 如果只是因为语法的问题的话,楼上的已经给出答案了。。。 --------------------编程问答-------------------- 楼主 %b.col001% 
改成"%"+b.col001+"%"试试
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,