Please start any new threads on our new site at http://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | 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)
 conversion error
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

arkiboys
Flowing Fount of Yak Knowledge

1433 Posts

Posted - 11/26/2012 :  05:55:04  Show Profile  Reply with Quote

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
Flowing Fount of Yak Knowledge

India
2242 Posts

Posted - 11/26/2012 :  06:14:55  Show Profile  Reply with Quote


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

--
Chandu
Go to Top of Page

arkiboys
Flowing Fount of Yak Knowledge

1433 Posts

Posted - 11/26/2012 :  06:46:07  Show Profile  Reply with Quote
Thanks
Go to Top of Page

bandi
Flowing Fount of Yak Knowledge

India
2242 Posts

Posted - 11/26/2012 :  06:47:02  Show Profile  Reply with Quote
quote:
Originally posted by arkiboys

Thanks


You are Welcome

--
Chandu
Go to Top of Page
  Previous Topic Topic Next 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.05 seconds. Powered By: Snitz Forums 2000