I'm trying to write a query that will allow me to include or exclude a filter in my where statement based on whether a parameter passed in is set to true or false. So far my statement is
IF @IncludeAttended = 'true' begin SELECT id, fullName, Address, PhoneNumber, NeverAttended FROM Guests_View WHERE (GroupID = @groupid) end else begin SELECT id, fullName, Address, PhoneNumber, NeverAttended FROM Guests_View WHERE (GroupID = @groupid) AND NeverAttended = 'false' end
So I'm trying to filter based on whether or not the guest has ever attended an event. Running the above SQL in Management Studio will get me appropriate results with no issues, but when I try to run this in SSRS, I get an error message
Conversion failed when converting the varchar value 'AM13425' to data type int.
I have tried several different statements and methods to find where this string might be, but I can't find it anywhere in the database, nor can I find it anywhere in the project itself, so as far as I can tell, the data doesn't exist. Wiping the table and repopulating it with fresh test data doesn't help either, the message just resurfaces. Also, if I take out the @IncludeAttended parameter, and just run only one half of the statement above (among various iterations), I can get the results back, but I need this report to allow this filtering. What else can I try, and where can I look for this phantom data that's causing me the problem?