1

I need help with my query:

When I send to the query a parameter with the value -1, I would like to get all the records (this parameter wont filter the results), otherwise filter according the value.

I was trying something like this:

WHERE  (StatusId = CASE WHEN @StatusId = - 1 
        THEN 
        @StatusId IS NULL 
        ELSE 
        StatusId = @StatusId   END)

Thanks.

4

3 回答 3

5
where  @StatusId = -1 or @StatusId = StatusId
于 2012-09-10T19:21:24.633 回答
2
 WHERE StatusId = @StatusId OR @StatusId = -1
于 2012-09-10T19:21:46.373 回答
2

我认为这会解决问题

Where (@StatusId = -1 or StatusId=@StatusId )
于 2012-09-10T19:23:31.577 回答