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 failed when converting the varchar to i

Author  Topic 

micnie_2020
Posting Yak Master

232 Posts

Posted - 2012-03-30 : 07:52:41
Dear All,

I have below OVal Field, Type = Varchar. It's contain string of array int[]. eg: 1231,1241

I want it to be pass into AID, field type=int.

But i getting error Conversion failed when converting the varchar value '1396,1395' to data type int.

Please Advise.

Thank you.

select STUFF(
(
SELECT
',' + cast(ANo as varchar)
from tblM where AID in
(
select replace(cast(OVal as int),',',''',''')
from tblB where ATID=1723)
FOR XML PATH('')
), 1, 1, ''
)

X002548
Not Just a Number

15586 Posts

Posted - 2012-03-30 : 10:10:46
it doesn't work that way..you will need dynamic sql



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

micnie_2020
Posting Yak Master

232 Posts

Posted - 2012-03-30 : 11:06:06
I found solution.
Thank you for reply.

Here is the link:-
http://www.codeproject.com/Articles/30681/Split-parameter-string-from-comma-seperator-in-SQL
Go to Top of Page
   

- Advertisement -