设表有两列
id name
1 A
1 B
2 A
3 B
求
如果输入A,B则返回1,输入A则返回2,输入B则返回3
id name
1 A
1 B
2 A
3 B
求
如果输入A,B则返回1,输入A则返回2,输入B则返回3
declare @table table (id int,name varchar(1))
insert into @table
select 1,'A' union all
select 1,'B' union all
select 2,'A' union all
select 3,'B'
declare @tj varchar(6);set @tj='A,B'
if(charindex(',',@tj)>0)
select max(id) from(select id from @table where name='A' union all
select id from @table where name='B') aa group by id having(count(*)>1)
else
select max(id) from @table where name=@tj