select test from test where test=@test@test有三个值"all","a","b"
我想当@test=all的时候选取所有数据,当@test=a的时候只选取test=a的数据,b同理.
不用if test='all' 然后怎样怎样这种判断能实现吗?新手,还请指教.谢谢.
我想当@test=all的时候选取所有数据,当@test=a的时候只选取test=a的数据,b同理.
不用if test='all' 然后怎样怎样这种判断能实现吗?新手,还请指教.谢谢.
Set @s = 'a'
select * from test
where test =
case when @s = 'x' then @s
when @s = 'y' then @s
else '' end
from test
where test=case when @test='all' then test else @test end
where test=@test or @test='all'
INSERT @tb SELECT 1,'a'
UNION ALL SELECT 2,'b'
UNION ALL SELECT 3,'c'
UNION ALL SELECT 4,'a'
UNION ALL SELECT 5,'b'
UNION ALL SELECT 6,'d'DECLARE @s varchar(10);
SET @s = 'a';SELECT * FROM @tb WHERE val = CASE WHEN @s = 'all' THEN val ELSE @s END
select a.test from test a where a.test=(select case when @test='all' then a.test else
@test end )
(a int,test char(10));
go
insert into aaa
select 1,'a'
union all
select 2,'b'
union all
select 3,'all'
go
declare @test char(10)
set @test='all'
select a.test from aaa a where a.test=(select case when @test='all' then a.test else
@test end )
2008测试通过
set @test = 'all'
select * from test where test= (case when @test ='x' then @test when @test='y' then @test else test end)