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.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 query error help?

Author  Topic 

akpaga
Constraint Violating Yak Guru

331 Posts

Posted - 2012-07-31 : 11:13:30
Hi friends

i have a sql query with a where condition

like this where (customername=@customername or @customername is null)

For the @customername parameter , i want to provide multiple values so i change the code
to
where( customername in (@customername) or @customername is null)...but when i am trying to pass in the parameter values the following error is popping up

'An expression of non-Boolean type specified in a context where condition is expected near ',''

Can someone guide me on how to do this...

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-07-31 : 11:20:11
you should be using it like

where ',' + @customername + ',' LIKE '%,' + customername + ',%'

and pass values as


@customername = 'customer1,customer2,custome3,..'


another method is to use string parsing function like below

http://visakhm.blogspot.com/2010/02/parsing-delimited-string.html

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

akpaga
Constraint Violating Yak Guru

331 Posts

Posted - 2012-07-31 : 12:01:58
Thank you visakh 16..was great help to me..
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-07-31 : 13:07:08
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

akpaga
Constraint Violating Yak Guru

331 Posts

Posted - 2012-07-31 : 17:01:11
Hi Visakh sorry but the error has come back again...

its due to the second part of the where condition @customername is null

when i remove it it works just fine... I just cannot understand
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-07-31 : 17:15:33
unless you give us full picture i dont we will be able to help you much

just adding @customername is null wont cause any error

so post us full query end explain what exactly you're trying to od

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -