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 |
|
raysefo
Constraint Violating Yak Guru
260 Posts |
Posted - 2010-06-30 : 08:32:40
|
| Hi,I want to retrieve data under some conditions like below;SELECT T.A,T.BFROM TABLE1 TWHERE T.X = PARAM1 AND T.Y = PARAM2what i need to do is, to retrieve data ;1) if no params (PARAM1 and PARAM2) entered2) if one of the params (PARAM1 or PARAM2) entered3) both of the params (PARAM1 and PARAM2) enteredIs there a way to constructa single SELECT statement? |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-06-30 : 08:35:03
|
| SELECT T.A,T.BFROM TABLE1 TWHERE (@param1 is null or T.X = @PARAM1) AND (@param2 is null or T.Y = PARAM2)MadhivananFailing to plan is Planning to fail |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
|
|
raysefo
Constraint Violating Yak Guru
260 Posts |
Posted - 2010-06-30 : 09:25:35
|
| thanks so much both of u. |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2010-06-30 : 11:21:02
|
quote: Originally posted by X002548 And no mention of t.x = COALESCE(@Param1,t.x)
That's the same ast.x = CASE WHEN @Param1 IS NULL THEN t.x ELSE @Param1 END So, CAOLESCE is not any better, unfortunatly. |
 |
|
|
|
|
|