日期:2014-05-17 浏览次数:20614 次
--drop table A
--drop table B
create table a(id int, name varchar(20))
insert into A
select 1 , '1002'
union all select 2 , '1003'
union all select 3 , '1004'
create table b(id int, namestr varchar(30))
insert into b
select 1 , '1002
------解决方案--------------------
1005
------解决方案--------------------
'
union all select 2 , '1004
------解决方案--------------------
'
union all select 3 , '1008
------解决方案--------------------
'
select id,
name,
case when exists
(
select 1
from b
where charindex('
------解决方案--------------------
'+a.name+'
------解决方案--------------------
','
------解决方案--------------------
'+b.namestr) > 0
)
then 1
else 0
end as flag
from a
/*
id name flag
1 1002 1
2 1003 0
3 1004 1
*/
WITH a(id,NAME) AS
(
SELECT 1,'1002' UNION ALL
SELECT 2,'1003' UNION ALL
SELECT 3,'1004'
)
,b (id,namestr) AS
(
SELECT 1,'1002
------解决方案--------------------
1005
------解决方案--------------------
' UNION ALL
SELECT 2,'1004
------解决方案--------------------<