Pattycake245
Programmer
I looked but could not find an existing thread which matches my problem. Basically I have a filtering app that has many variables passed to a stored proc. Some of the variables passed are actual arithmetic operators, =, >=, <=
and so on. Currently I have conditions in my where clause of my query like so:
if(@rsrch_ni_con <> '')
begin
select @SQLString = @SQLString + ' and a.per_rsch_ni ' + @rsrch_ni_con + ' ' + @rsrch_ni_no + ' '
end
Which, if printed out would look like this:
and a.per_rsch_ni = 90 as an example.
I am trying to rewrite this query using case statements instead of dynamic strings. If I was not passing the arithmetic parameter this would be easy, something like:
and a.per_rsch_ni = case when @rsrch_vg_no <> '' then @rsrch_vg_no else a.per_rsch_ni end
this is assuming the query is using "=".
Is it even possible to write case statements for aritmetic operators? Hopefully this makes sense.
Tim
and so on. Currently I have conditions in my where clause of my query like so:
if(@rsrch_ni_con <> '')
begin
select @SQLString = @SQLString + ' and a.per_rsch_ni ' + @rsrch_ni_con + ' ' + @rsrch_ni_no + ' '
end
Which, if printed out would look like this:
and a.per_rsch_ni = 90 as an example.
I am trying to rewrite this query using case statements instead of dynamic strings. If I was not passing the arithmetic parameter this would be easy, something like:
and a.per_rsch_ni = case when @rsrch_vg_no <> '' then @rsrch_vg_no else a.per_rsch_ni end
this is assuming the query is using "=".
Is it even possible to write case statements for aritmetic operators? Hopefully this makes sense.
Tim