Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
dermotb
Starting Member
2 Posts |
Posted - 2005-08-15 : 19:10:33
|
| Hi,My query is like thisSELECT * FROM books WHERE category = '1st value'or category = '2nd value' or or category = ...and so on...But can someone help to explain how I can use this where clause when I don't know beforehand how many values in my WHERE clause?How do I dynamically generate the SQL.Thanks a lot for looking.D |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2005-08-15 : 19:15:30
|
| http://www.sqlteam.com/item.asp?ItemID=11499Tara |
 |
|
|
dermotb
Starting Member
2 Posts |
Posted - 2005-08-15 : 19:39:38
|
| Thanks for the quick response.Would you say that's the only way/best wayi.e. is there a simpler (pre-sqlserver2000) way to do itor would that be a VBScript question?Thanks,Dermot |
 |
|
|
Lumbago
Norsk Yak Master
3271 Posts |
Posted - 2005-08-16 : 03:51:16
|
| SELECT * FROM books WHERE category IN ('1st value', '2nd value', '3rd value')--Lumbago"Real programmers don't document, if it was hard to write it should be hard to understand" |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-08-16 : 04:02:36
|
| >>SELECT * FROM books WHERE category IN ('1st value', '2nd value', '3rd value')This is possible only if we know how many values to be includedOne other possible way is to insert the values to other table called Category and write querySELECT * FROM books B WHERE exists (select Category from Category where Category=B.Category)MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|