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

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -