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 |
|
hog
Constraint Violating Yak Guru
284 Posts |
Posted - 2006-02-14 : 16:41:11
|
| Is it possible to use a case statement similar to this to return from the required select?CASE WHEN LEN(@P) > 0 THEN SELECT * FROM MyTab WHERE cust_code = @PWHEN LEN(@Nm) > 0 THEN SELECT *FROM MyTab WHERE name = @NmELSESELECT * FROM MyTabENDI have tried various forms of passing this case statement to a select statement but just get incorrect syntax Any ideas? |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2006-02-14 : 17:01:51
|
| No that is not possible. Please post an explanation of what you are trying to do.Tara Kizeraka tduggan |
 |
|
|
hog
Constraint Violating Yak Guru
284 Posts |
Posted - 2006-02-14 : 17:10:16
|
| I have a table with all the formated data in it. The final process is to return to the user the contents of this table based on the filter they pass. So if @P > 0 return filtered by @P if @Nm > o then return filtered by @Nm.Guess I am looking at multiple IF statements then? |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2006-02-14 : 17:11:19
|
| If you are looking to implement a dynamic WHERE clause, then you'll need to use COALESCE function. Here is the article that explains it:http://www.sqlteam.com/item.asp?ItemID=2077Tara Kizeraka tduggan |
 |
|
|
hog
Constraint Violating Yak Guru
284 Posts |
Posted - 2006-02-14 : 17:25:31
|
| Sad it takes me so much brain power to grasp such things, but although I do not fully understand how it works and can see how it will resolve my problem, and help me revamp current procedures I have written.Thnx :) |
 |
|
|
hog
Constraint Violating Yak Guru
284 Posts |
Posted - 2006-02-14 : 19:15:22
|
| RESULT!I understand it now and it works perfect :) THNX..... |
 |
|
|
|
|
|