Forum Moderators: open

Message Too Old, No Replies

IN clause. How to select nothing in SQL Server

         

NooK

2:24 pm on Nov 8, 2007 (gmt 0)

10+ Year Member



I am trying to setup a filter with a couple of checkboxes in my website which will work in such a way that the user clicks on a checkbox to add that filter to the table below.

Basically all it does is add more arguments to an IN clause such as

SELECT...FROM * WHERE....AND field IN (valueList)...

I would like to allow the user to basically select no filter to show and empty table, is there anyway to do that?

I have tried just having nothing in the IN clause like this

SELECT...FROM * WHERE....AND field IN ()...

but I get a complaint.

I am using SQL Server 2005.

Best Regards

NooK

LifeinAsia

4:46 pm on Nov 8, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



You'll have to setup the logic in your application program (ASP, PHP, whatever) and only include the IN clause in the query if at least one checkbox was selected.

syber

8:33 pm on Nov 8, 2007 (gmt 0)

10+ Year Member



You could always seed the IN clause with a NULL.

NooK

11:35 am on Nov 13, 2007 (gmt 0)

10+ Year Member



Thanks. Seeding it with NULL worked like a charm.

Best Regards

NooK