sql server - Conditionally appending AND to where clause in SQL Select statement -
i have searched on , find questions on conditional where clauses
nothing conditionally appending and
piece onto where clause
. i'm not sql/database person, i'm it
area has been thrown "go try fix it" problem today because our regular database people gone. have basic programming concepts , knowledge sql
foreign animal me.
i have simple:
select abc table sdate=@somedt
but need add:
and otherdt=@otherdt
but if @otherdt
not null. if null don't want add and
part @ all. i've tried few ways keeps giving me error. appreciated. last unsuccessful try:
select abc table sdate=@somedt if @otherdt not null begin , otherdt=@otherdt end
select abc table sdate = @somedt , (@otherdt null or otherdt = @otherdt)
Comments
Post a Comment