SQL Server : select with "Value or All" -
i have table t1
columns id1
, id2
.
i need write 1 "select" stored procedure this
create sp_gett1byid1andid2 @id1 varchar(50), @id2 varchar(50) begin select * t1 // if (id1 = "all" , id2 = "all") have return data in table t1 // if (id1 = "all" , id2 != "all") have filter data according id2 // if (id1 != "all" , id2 = "all") have filter data according id1 // if (id1 != "all" , id2 != "all") have filter data according id1 , id2 end
select * your_table (@id1 = 'all' or id1 = @id1) , (@id2 = 'all' or id2 = @id2)
Comments
Post a Comment