请教:一条SQL查找语句(急用)
要模糊查找记录
SELECT *
FROM mt
WHERE (picid IN
(SELECT DISTINCT pid
FROM canpin))
如果改成
SELECT *
FROM mt
WHERE (picid like '%
(SELECT DISTINCT pid
FROM canpin)) % '
就出错,请问应该怎样实现呢?
------解决方案--------------------SELECT *
FROM mt
WHERE (picid like '% '+
(SELECT DISTINCT cast( pid as varchar)
FROM canpin)+ '% ')
---?
------解决方案----------------------如果pid不是字符型
select * from mt as tmp
where exists(select 1 from canpin where tmp.picid like rtrim(pid)+ '% ')