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)
 conversation failed converting nvarchar

Author  Topic 

magmo
Aged Yak Warrior

558 Posts

Posted - 2015-05-06 : 07:12:18
Hi

I have a stored procedure that I pass in a semicolon separated string and try to find all ID's that match. But I get this error "Conversion failed when converting the nvarchar value '11;10' to data type int." on this line..


AND (';'+@AvdId+';' LIKE '%;'+CAST(dbo.SurveyAnswerInfo.AvdId AS VARCHAR(32))+';%' OR @AvdId = 0 OR @AvdId = '0')


Shouldn't this work?

Kristen
Test

22859 Posts

Posted - 2015-05-06 : 07:35:34
is @AvdId declared as varchar (rather than int/numeric) ?

Bit worried you have

OR @AvdId = 0 OR @AvdId = '0'

as you only need either the Numeric OR the String ... but not both!!

Testing for

@AvdId = 0

will DEFINITELY fail if @AvdId is a string which does NOT implicitly convert to an INT - such as "11;10"

Go to Top of Page

magmo
Aged Yak Warrior

558 Posts

Posted - 2015-05-06 : 07:45:02
Yes its declared as varchar ..

@AvdId nVarChar(500)

Go to Top of Page

magmo
Aged Yak Warrior

558 Posts

Posted - 2015-05-06 : 08:04:05
I removed the = 0 part and now it seem to work
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2015-05-06 : 09:24:12
Go to Top of Page
   

- Advertisement -