sqlsql-serverrazor-3

SQL 2 where clauses


I have a fairly simple query which I am trying to execute on my website, all though, it just won't work. I'm using 2 where clauses, and yes, I have seen many of the other questions about multiple where clauses, my query is just very different from theirs as their queries are much more complicated and advanced, and so I can't really get the solutions to work for me.

Here's my query;

SELECT * FROM ImpoundReports WHERE (UserId = @0 AND Released = 0)

The query "works", as in it doesn't give me any error, it just doesn't pull out the report as it's supposed to.

UserId is an int. Released is a bit.

UserId = @0 is a scalar variable used in my Razor code.

Thank you in advance.


Solution

  • Looking at the question if Released is bit, then its possible values are true, false and null (if null is acceptable)

    so the possible result queries are..

        SELECT * FROM ImpoundReports WHERE (UserId = @0 AND Released is null)
        SELECT * FROM ImpoundReports WHERE (UserId = @0 AND Released is true)
        SELECT * FROM ImpoundReports WHERE (UserId = @0 AND Released is false)