Skip to content
Advertisement

SQL Where clause conditional assignment based on another parameter

I need to generate a report where the user can choose All Issues, Open Issues, or Closed issues in a radio button. In my view I have a isClosed bit column. If I didn’t have the All Issues radio box I’d just do:

SELECT *
FROM MyView
WHERE isClosed = @ViewClosedRecords

However I need to remove the isClosed = @ViewClosedRecords condition when the @ViewAllRecords = true. How would I do this?

Advertisement

Answer

SELECT *
FROM MyView
WHERE @ViewAllRecords OR isClosed = @ViewClosedRecords
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement