SQL server IF begin statement in where function -


i'm trying create following in statement.

    registration_date >=@startdate , registration_date < dateadd(day,1,@enddate)          , if @affiliateid null begin channel in (select value dbo.split(',',@channel)) end               else affiliate_id in (select value dbo.split(',', @affiliateid))         , registration_channel in (select value dbo.split(',', @channel)) 

so, trying if @affiliateid null, use @channel input affiliate ids, if not use specific @affiliateid, irrespective of channels.

is there way make work?

select  *    mytable   date(registration_date) between @startdate , @enddate         , exists         (         select  null            dbo.split(',', coalesce(@affiliateid, @channel))           value = case when @affiliateid null channel else affiliateid end         )         , exists         (         select  null            dbo.split(',', @channel)           value = registration_channel         ) 

in sql server 2008, date(column) sargable expression.


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -