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 |
RexHelios
Starting Member
3 Posts |
Posted - 2008-12-09 : 13:21:56
|
Hi,I have a table with the following structure and dataState Price----- -----NULL $100CA $120TX $75IA $60I have one of the 50 states in a variable. Now I need to extract the corresponding price from the table above. Whenever there is match for the state, I would select the corresponding price. But if there is no match found, I should get the generic price where State is NULL.How can I write a SQL Statement/T-SQL block to achieve this? Any help or inputs will be grately appreciated.Regards,RexHelios |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-12-09 : 13:28:20
|
[code]SELECT TOP 1 *FROM TableWHERE State=@StateOR State IS NULLORDER BY COALESCE(State,'ZZZZZZZ') ASC[/code] |
|
|
RexHelios
Starting Member
3 Posts |
Posted - 2008-12-09 : 14:30:49
|
Thank you very much, Visakh16. It worked like a charm!Regards,RexHelios |
|
|
|
|
|