sql server - Conditional WHERE clause to combine two queries -
i have large select into
statement in t-sql script , have 2 separate select into
's differing 1 or
condition in where
clause. if variable @cycle_nbr = 1
have doing 1 select into
, if @cycle_nbr = 0
have doing other select into
.
i wondering if there way in 1 select into
@cylce_nbr
condition in where
itself.
here where
clause:
where ((a.gl_indicator = '0' or a.gl_indicator = '1') , (a.gl_ins_type = '1' or a.gl_ins_type = '3' ) , rel_file_nbr null , a.alpha_line not '%z' , mis_process_dt >= @start_dt , acctg_cyc_ym = @acctg_cyc) or (a.prem_sys_cd='t' , acctg_cyc_ym = @acctg_cyc )
i want last condition or (a.prem_sys_cd='t' , acctg_cyc_ym = @acctg_cyc )
in there if @cycle_nbr = 1
. can put if
in there somewhere make work? or have stick if(@cycle_nbr = 1) run select else run other select
?
include variable in or statement, i.e.,
or (a.prem_sys_cd='t' , acctg_cyc_ym = @acctg_cyc , @cycle_nbr = 1)
Comments
Post a Comment