Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Instead of OR in WHERE clause
Message
From
04/02/2014 10:36:48
Mike Yearwood
Toronto, Ontario, Canada
 
 
To
04/02/2014 10:17:01
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Environment versions
SQL Server:
SQL Server 2008
Application:
Web
Miscellaneous
Thread ID:
01593065
Message ID:
01593115
Views:
32
>>You mean with the IN() clause. Ussually what I do is to put all the keys in a temp table and perform a join with it. Its possible to convert a comma delimited list passed as a parameter into a temp table. Eg
>
>Yes, this is what I am doing now but only if I have a certain number of keys. The IN clause would provide a better and cleaner approach up to a certain number.

I'm sorry. I have to disagree with that.

SELECT * FROM TABLE WHERE FIELD IN (1,2,3,4,5,7,8,9). What number is missing? How long does it take you to determine one is missing? That's just single digit ID's. Why should you have to be concerned with that?

select * from table where field in (select key from userschoices) is much, much cleaner. It provides far more than 32000 keys. If I understand the intent, the user can select many ids - whether you concatenate them into a string or add them to a table - is little difference to the user. But using a single technique - adding them to a table and not trying to decide if you want to use IN in one case and a temp table in another is also much easier on you.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform