SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 query error help?
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

akpaga
Constraint Violating Yak Guru

USA
283 Posts

Posted - 07/31/2012 :  11:13:30  Show Profile  Reply with Quote
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...

Edited by - akpaga on 07/31/2012 11:19:15

visakh16
Very Important crosS Applying yaK Herder

India
47069 Posts

Posted - 07/31/2012 :  11:20:11  Show Profile  Reply with Quote
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

USA
283 Posts

Posted - 07/31/2012 :  12:01:58  Show Profile  Reply with Quote
Thank you visakh 16..was great help to me..
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
47069 Posts

Posted - 07/31/2012 :  13:07:08  Show Profile  Reply with Quote
welcome

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

Go to Top of Page

akpaga
Constraint Violating Yak Guru

USA
283 Posts

Posted - 07/31/2012 :  17:01:11  Show Profile  Reply with Quote
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

India
47069 Posts

Posted - 07/31/2012 :  17:15:33  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000