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 |
|
nsap
Starting Member
1 Post |
Posted - 2011-02-03 : 19:03:41
|
| I am tring to get rows that have New South Wales or Queensland in the State column. I want to use a @State parameter and set this to different values as required.1.) This works fineSelect Statefrom CheckboxV3where isnull ( State , '' ) in ( 'New South Wales','Queensland' )2.) This does not return anything ??? why not?declare @State VARCHAR(100)set @State = '''New South Wales'',''Queensland'''Select Statefrom CheckboxV3where isnull ( State , '' ) in ( @State ) |
|
|
dataguru1971
Master Smack Fu Yak Hacker
1464 Posts |
Posted - 2011-02-03 : 20:33:45
|
The string doesn't just build itself into the SQL like that. It is different than if you only wanted 1 stateThis would work:set @State ='New South Wales'Select Statefrom CheckboxV3where State = @StateFor the IN clause variable application, you need to build the whole select statement and add the variable to the string, so something like this[/code]SELECT @SQL = 'Select [State]from CheckboxV3where in ('+ @state + ' )'sp_ExecuteSQL @SQL[/code] Poor planning on your part does not constitute an emergency on my part. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2011-02-04 : 05:14:52
|
| Also search for Passing Arrays+ SQL Server in google/bingMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|