我的表格T1
包含ID1
,ID2
列。
我需要像这样编写一个“选择”存储过程
Create SP_GetT1ByID1AndID2
@id1 varchar(50), @id2 varchar(50)
as
begin
Select *
from T1
where
// If (ID1 = "All" and ID2 = "All") so we have to return all the data in the table T1
// If (ID1 = "All" and ID2 != "All") so we have filter the data according to ID2
// If (ID1 != "All" and ID2 = "All") so we have filter the data according to ID1
// If (ID1 != "All" and ID2 != "All") so we have filter the data according to ID1 and ID2
end
答案 0 :(得分:0)
select * from your_table
where (@id1 = 'All' or ID1 = @id1)
and (@id2 = 'All' or ID2 = @id2)