name pass area positon
wujilin 222222 AA 清点员 123456
wuqiao 4567 BB 清点员 2344
xyz 222222 AA,BB,CC 区域财务 4
xx 222222 44 区域DC 777
ww 22 46 区域财务 999
ew 33 34 区域DC 555
rfv 555 CC 清点员 33
4rfv 33 All 总仓 区域财务负责 AA,BB,CC区域 我想得到
name name2
wujilin xyz
wuqiao xyz
rfv xyzselect a.UserName,b.UserName
from WujilinTwoTest a,WujilinTwoTest b
where charindex(a.AreaCode,b.AreaCode)>0
and b.UserName ='xyz'
and a.Position='清点员'可是一直得不到结果 请大家帮我看看为什么 谢谢
wujilin 222222 AA 清点员 123456
wuqiao 4567 BB 清点员 2344
xyz 222222 AA,BB,CC 区域财务 4
xx 222222 44 区域DC 777
ww 22 46 区域财务 999
ew 33 34 区域DC 555
rfv 555 CC 清点员 33
4rfv 33 All 总仓 区域财务负责 AA,BB,CC区域 我想得到
name name2
wujilin xyz
wuqiao xyz
rfv xyzselect a.UserName,b.UserName
from WujilinTwoTest a,WujilinTwoTest b
where charindex(a.AreaCode,b.AreaCode)>0
and b.UserName ='xyz'
and a.Position='清点员'可是一直得不到结果 请大家帮我看看为什么 谢谢
select a.UserName,b.UserName
from WujilinTwoTest a,WujilinTwoTest b
where charindex(','+a.AreaCode+',',','+b.AreaCode+',')>0
and b.UserName ='xyz'
and a.Position='清点员'
go
insert WujilinTwoTest select 'wujilin', 222222, 'AA', '清点员'
insert WujilinTwoTest select 'wuqiao', 4567, 'BB', '清点员'
insert WujilinTwoTest select 'xyz', 222222, 'AA,BB,CC', '区域财务'
insert WujilinTwoTest select 'xx', 222222, 44, '区域DC'
insert WujilinTwoTest select 'ww', 22, 46, '区域财务'
insert WujilinTwoTest select 'ew', 33, 34, '区域DC'
insert WujilinTwoTest select 'rfv', 555, 'CC' , '清点员'
insert WujilinTwoTest select '4rfv', 33 ,'All' , '总仓' go
select a.UserName,b.UserName name2
from WujilinTwoTest a,WujilinTwoTest b
where charindex(a.AreaCode,b.AreaCode)>0
and b.UserName ='xyz'
and a.Position='清点员' go
drop table WujilinTwoTest
go
/*
UserName name2
-------------------- --------------------
wujilin xyz
wuqiao xyz
rfv xyz(所影响的行数为 3 行)*/
go
insert WujilinTwoTest select 'wujilin', 222222, 'AA', '清点员'
insert WujilinTwoTest select 'wuqiao', 4567, 'BB', '清点员'
insert WujilinTwoTest select 'xyz', 222222, 'AA,BB,CC', '区域财务'
insert WujilinTwoTest select 'xx', 222222, 44, '区域DC'
insert WujilinTwoTest select 'ww', 22, 46, '区域财务'
insert WujilinTwoTest select 'ew', 33, 34, '区域DC'
insert WujilinTwoTest select 'rfv', 555, 'CC' , '清点员'
insert WujilinTwoTest select '4rfv', 33 ,'All' ,'总仓'select m.name ,
n.name
from WujilinTwoTest m , WujilinTwoTest n
where charindex(m.area , n.area) > 0 and m.name <> n.namedrop table WujilinTwoTest/*
name name
-------------------- --------------------
wujilin xyz
wuqiao xyz
rfv xyz(所影响的行数为 3 行)*/
go
insert WJLTest
select 'wujilin', 222222, 'AA', '清点员' union all
select 'wuqiao', 4567, 'BB', '清点员' union all
select 'xyz', 222222, 'AA,BB,CC', '区域财务' union all
select 'xx', 222222, '44', '区域DC' union all
select 'ww', 22, '46', '区域财务' union all
select 'ew', 33, '34', '区域DC' union all
select 'rfv', 555, 'CC' , '清点员' union all
select '4rfv', 33 , 'All' , '总仓'select a.UserName 清点员,b.UserName 区域财务
from WJLTest a,WJLTest b
where charindex(a.Area,b.Area)>0
and b.UserName ='xyz'
and a.Position='清点员'
/*
清点员 区域财务
-------------------- --------------------
wujilin xyz
wuqiao xyz
rfv xyz(3 行受影响)
*/ 你给出的表字段和语句中的字段不对应
where 条件的问题吧,你依次去掉条件看一下