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 2005 Forums
 Transact-SQL (2005)
 Conversion failed when converting the nvarchar val

Author  Topic 

kamii47
Constraint Violating Yak Guru

353 Posts

Posted - 2008-09-01 : 07:10:02
I have a query where my parameter is provided as a string as '1 ,2 ,3'
it is used in a In query.The numbers are int identity columns in the database.I have no other way of changing the parameter.
But I can change the query.[But parameter is given to me as comma separated string]

Follwing is my current query

Select users from tbl1 where userid in ('1 , 2 , 3 ' )
which is giving the error
Conversion failed when converting the nvarchar value '1 , 2 , 3 ' to data type int.

Kamran Shahid
Sr. Software Engineer(MCSD.Net,MCPD.net)
www.netprosys.com

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-09-01 : 07:23:54
declare @userid varchar(100)
set @userid='1,2,3'
Select users from tbl1 where ','+@userid+',' like '%,'+cast(userid as varchar(10))+',%'

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

kamii47
Constraint Violating Yak Guru

353 Posts

Posted - 2008-09-01 : 07:31:07
Thanks it work could u please explain a little

Kamran Shahid
Sr. Software Engineer(MCSD.Net,MCPD.net)
www.netprosys.com
Go to Top of Page
   

- Advertisement -