以下のクエリを確認してください
DECLARE @status varchar(1)
DECLARE @code varchar(50)
Set @status = '0'
select id,code from MasterTable where
('07/31/2012' between StartDate and EndDate) and
Case when @status = '0' and Status=@status then 1 end = 1
このクエリは私には機能しますが、機能しません@Status=1
次のようなクエリが必要です
if @Status = '0'
select id,code from MasterTable where
('07/31/2012' between StartDate and EndDate) and Status = @Status
if @code <> '0'
select id,code from MasterTable where
('07/31/2012' between StartDate and EndDate) and Status = @Status and code =@code
else
select id,code from MasterTable where
('07/31/2012' between StartDate and EndDate)
if @code <> '0'
select id,code from MasterTable where
('07/31/2012' between StartDate and EndDate) and Status = @Status and code =@code
case when ステートメントを使用してこれを達成するにはどうすればよいですか?