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 |
|
sparrow37
Posting Yak Master
148 Posts |
Posted - 2009-11-04 : 13:52:55
|
| Hi all,I have following SQL query which shows cities based on stateSELECT [USCityID], [USCityName], [USStateID] FROM [USCity] WHERE [USStateID] = '3'and [USCityName] <> '' order by [USCityName]I want to change it so that if i pass it 38 as stateid then it shows all states and behave like thisSELECT [USCityID], [USCityName], [USStateID] FROM [USCity] WHERE [USCityName] <> '' order by [USCityName]How can i do this ?Please suggest me solution to it.Regards,Asif Hameed |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2009-11-04 : 14:16:16
|
| WHERE (USStateID = @StateID ID OR (@StateID = 38 and stateID is not null ) and [USCityName] <> ''JimEveryday I learn something that somebody else already knew |
 |
|
|
sparrow37
Posting Yak Master
148 Posts |
Posted - 2009-11-04 : 14:20:49
|
| Hi jim:Thanks for the response. Can you please paste whole query. I am getting syntax error. I think some paranthesis not closed.Regards,Asif Hameed |
 |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2009-11-04 : 14:26:00
|
| You are correct, a parenthesis is not closed. The problem is in here. Can you spot it?WHERE (USStateID = @StateID ID OR (@StateID = 38 and stateID is not null)and [USCityName] <> ''JimEveryday I learn something that somebody else already knew |
 |
|
|
sparrow37
Posting Yak Master
148 Posts |
Posted - 2009-11-04 : 14:31:53
|
| where will this paranthesis close ? actualquery is:SELECT [USCityID], [USCityName], [USStateID] FROM [USCity] WHERE [USStateID] = '3'and [USCityName] <> '' order by [USCityName]Regards,Asif Hameed |
 |
|
|
|
|
|