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)
 conversion error

Author  Topic 

arkiboys
Master Smack Fu Yak Hacker

1433 Posts

Posted - 2012-11-26 : 05:55:04

declare @value1 int = 2
declare @value2 int = 4
declare @Allvalues varchar(100) = cast(@value1 as varchar(10)) + ',' + cast(@value2 as varchar(10))

field1 is an int datatype
select field1, field2 from tblMain where field1 = @value1
select field1, field2 from tblMain where field1 = @value2

Question:
HOw do I get the following to work please?
Error is:
Conversion failed when converting the varchar value '2, 4' to data type int.
select field1, field2 from tblMain where field1 in (@Allvalues)

Thanks

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2012-11-26 : 06:14:55


select field1, field2
from tblMain
where ',' + CAST( field1 AS VARCHAR(50)) + ',' LIKE '%,' + @Allvalues + ',%'

--
Chandu
Go to Top of Page

arkiboys
Master Smack Fu Yak Hacker

1433 Posts

Posted - 2012-11-26 : 06:46:07
Thanks
Go to Top of Page

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2012-11-26 : 06:47:02
quote:
Originally posted by arkiboys

Thanks


You are Welcome

--
Chandu
Go to Top of Page
   

- Advertisement -