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