Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL - Creating A Conditional Where Clause For This Simple Query

I've been trying to create a conditional where clause for my query below but I keep seeing so many alternatives I'm not sure what to use in this case.

What I need is something along the lines of this: (though of course this code is wrong)

where casCaseType='m'
  and casCurrentWorkflowID=990
  and cmsDateCreated between @FromDate and @ToDate

 CASE @WFStatus
      WHEN @WFStatus=1 then eveworkflowID<100
      WHEN @WFStatus=2 then eveworkflowID<200
      WHEN @WFStatus=3 then eveworkflowID<300
      WHEN @WFStatus=4 then eveworkflowID<400
 ELSE 0
 END

So when I choose the WFStatus parameter as 1, it would automatically engage that section of the where clause bringing out only those results with a eveworkflowID which is less than 100.

Any help would be greatly appreciated!

Thanks

like image 621
TJH Avatar asked May 14 '26 23:05

TJH


2 Answers

WHERE casCaseType='m'
  AND casCurrentWorkflowID=990
  AND cmsDateCreated between @FromDate and @ToDate

  AND eveworkflowID < 
      CASE @WFStatus
        WHEN 1 THEN 100
        WHEN 2 THEN 200
        WHEN 3 THEN 300
        WHEN 4 THEN 400
        ELSE 0
      END
like image 56
ypercubeᵀᴹ Avatar answered May 19 '26 03:05

ypercubeᵀᴹ


I am not sure, but if I understand correctly: ... AND eveworkflowID < @WFStatus * 100

like image 30
Guillaume Poussel Avatar answered May 19 '26 03:05

Guillaume Poussel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!