May 7, 2009 at 2:01 pm
Hi
I got it. You have to specify an alias for the outer table. Since your table name is "holddups" and you refer it within your sub-query you cannot specify "NUM1 = holddups.NUM1". This refers to itself. Try this:
USE tempdb
SELECT
NUM1,
STUFF(
(
SELECT ',' + SERVIZI
FROM holddups
WHERE NUM1 = h1.NUM1
FOR XML PATH(''))
, 1, 1, '')
FROM holddups h1
GROUP BY NUM1
Greets
Flo
May 7, 2009 at 2:31 pm
Florian Reischl (5/7/2009)
HiI got it. You have to specify an alias for the outer table. Since your table name is "holddups" and you refer it within your sub-query you cannot specify "NUM1 = holddups.NUM1". This refers to itself. Try this:
USE tempdb
SELECT
NUM1,
STUFF(
(
SELECT ',' + SERVIZI
FROM holddups
WHERE NUM1 = h1.NUM1
FOR XML PATH(''))
, 1, 1, '')
FROM holddups h1
GROUP BY NUM1
Greets
Flo
Good catch Flo. I missed that one myself. I starting thinking about possible data issues.
May 7, 2009 at 2:37 pm
Lynn Pettis (5/7/2009)
Good catch Flo. I missed that one myself. I starting thinking about possible data issues.
Thanks Lynn! Did something likewise today at work and saw that something seems to be missing.
May 8, 2009 at 1:06 am
Lynn/Flo,
Thanks for all your help, the query works the table is now down to 5000 rows instead of 1M.
Des.
Viewing 4 posts - 16 through 18 (of 18 total)
You must be logged in to reply to this topic. Login to reply