我想从testTable
if中获取所有记录(6 行) a = 4
。4
是 SP 中的默认参数。
create table testTable(a int, b int, c int)
go
insert into testTable values(2, 101, 100000)
go
insert into testTable values(2, 101, 100001)
go
insert into testTable values(3, 101, 100002)
go
insert into testTable values(3, 102, 100003)
go
insert into testTable values(4, 1, 100004)
go
insert into testTable values(4, 1, 100005)
go
create proc SPtest
@a int = 4,
@b int = 1
as
select * from testTable where a = @a and b = @b
exec SPtest 2, 101
以上效果很好。但我需要这样的东西:
declare @a int
set @a = 4
select *
from testTable
where a = case @a when 4 then select distinct a from testTable end