subquery - Conditional SQL Statement -
subquery - Conditional SQL Statement -
i inquire if possible create sql statement if or similar structure. have 2 queries , combine them one. difference between 2 1 has additional , conditions on clause. tried doing select case, not successful. create parameter "test" take 1 or 2, , status should determine query run. here queries...
query 1
select id,avg(b.vol) pvol (select var1 id, sum(vol) pvol table1 var1='xyz' , date_d>'10/28/2013' , date_d<'10/31/2013' , customer='market' , market='south' , project=0 grouping var1,date_d) b grouping id
query 2
select id,avg(b.vol) pvol (select var1 id, sum(vol) pvol table1 var1='xyz' , date_d>'10/28/2013' , date_d<'10/31/2013' , project=0 grouping var1,date_d) b grouping id
you create sproc accepts "test" parameter hope build if statement around.
create procedure --sprocname ( @test int ) begin set nocount on if @test = --bool select statement 1 else select statement 2 end
sorry poor format in hurry setting
sql subquery
Comments
Post a Comment