views:

98

answers:

5

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?

+2  A: 
SELECT *
FROM MyView
WHERE @ViewAllRecords OR isClosed = @ViewClosedRecords

Kindness,

Dan

Daniel Elliott
I try this and query builder says "Invalid column name true" and then it changes it to `(isClosed = @ViewClosedRecords) OR (ProjectID = @RequestedProjectID) AND (true = @ViewAllRecords)` but still errors.
jamone
Edited a little .. try again
Daniel Elliott
+1  A: 
select *
from MyView
WHERE isClosed = @ViewClosedRecords
OR @ViewAllRecords

And set @ViewAllRecords parameters to true when user selects "All Issues" in the radio button.

Pablo Santa Cruz
+1  A: 
WHERE
(@ViewAllRecords = false AND isClosed = @ViewClosedRecords)
OR 
(@ViewAllRecords = true)
Coronatus
+1  A: 

The following will give you all rows with isClosed = @ViewClosedRecords. If @ViewAllRecords = true then it will return all rows and ignore isClosed.

SELECT *
FROM MyView
WHERE isClosed = @ViewClosedRecords
   OR @ViewAllRecords = true
Peter Lang
for some reason it wouldn't equate true as a boolean, but after I set it as a string and did = 'true' it works.
jamone
+1  A: 
WHERE (@ViewAllRecords <> true AND isClosed = @ViewClosedRecords)
brydgesk