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 |
|
daman
Yak Posting Veteran
72 Posts |
Posted - 2008-09-16 : 14:48:33
|
Newbie questionI'd like to select the price from a table based on 3 conditions (min, max, equal).There will be at least one condition that is not null. select mid from Pricewhere if @min is not null thenmid >= @minif @max is not null thenand mid <= @maxif @equal is not null thenand mid= @equal |
|
|
Vinnie881
Master Smack Fu Yak Hacker
1231 Posts |
Posted - 2008-09-16 : 15:09:09
|
tryselect mid from Pricewhere coalesce(@min,Mid) >= Midand coalesce(@Max,Mid) <= Midand coalesce(@Equal,Mid) = Mid It's been a long day, I reversed the order, the code above should work now. Success is 10% Intelligence, 70% Determination, and 22% Stupidity.\_/ _/ _/\_/ _/\_/ _/ _/- 881 |
 |
|
|
bfoster
Starting Member
30 Posts |
Posted - 2008-09-16 : 15:16:37
|
| I guess I have a different interpretation of your question. My query will not produce the same results as the one above. Here's my suggestion which may or may not be what you're looking for.select mid from Pricewhere (@min is null or mid >= @min)and (@max is null or mid <= @max)and (@equal is null or mid = @equal) |
 |
|
|
daman
Yak Posting Veteran
72 Posts |
Posted - 2008-09-16 : 15:57:58
|
| bfoster got what I wanted to do. Thanks you both for your time, gentlemen. |
 |
|
|
|
|
|