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
 General SQL Server Forums
 New to SQL Server Programming
 Stuff Function not working for Integer columns

Author  Topic 

jim_jim
Constraint Violating Yak Guru

306 Posts

Posted - 2011-05-12 : 09:09:01
Below is my query using stuff function which works fine when i concatenate a string column but get conversion error when trying the same on a integer column.

Query
SELECT

Distinct ReqInfo,STUFF((

SELECT

',' + RID

FROM Reports WHERE ReqInfo= A.ReqInfo

FOR XML PATH('')

),1,1,'') AS CustID

FROM Reports A



Error Message
Conversion failed when converting the varchar value ',' to data type int.

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2011-05-12 : 09:11:47
SELECT

Distinct ReqInfo,STUFF((

SELECT

',' + convert(varchar(n),RID)

FROM Reports WHERE ReqInfo= A.ReqInfo

FOR XML PATH('')

),1,1,'') AS CustID

FROM Reports A

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2011-05-12 : 09:12:26
convert(varchar(10),RID)


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2011-05-12 : 09:13:03




No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

jim_jim
Constraint Violating Yak Guru

306 Posts

Posted - 2011-05-12 : 09:18:05
Thank You ALL
Go to Top of Page

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2011-05-12 : 09:26:49
I'm going to start keeping track of how many times I've sniped you. Must be that your posts have further to travel!

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

jim_jim
Constraint Violating Yak Guru

306 Posts

Posted - 2011-05-12 : 10:20:01
you have been great to get me help whenever needed.
I will also keep track of how many times you responded to my posts
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2011-05-12 : 10:21:20
quote:
Must be that your posts have further to travel!



That's a fine excuse.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -