SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Concatenate Rows (PowerPivot)


Concatenate Rows (PowerPivot)

Author
Message
joshcas
joshcas
SSC Rookie
SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)

Group: General Forum Members
Points: 31 Visits: 20
Hi,

Today I'm facing a very complicated challenge , I have a connection trough PowerPivot to an Excel file and I'm trying to concatenate the rows into one single column , here is how my data looks :

Sales Order Identifier..........Billing Document Identifier................Billing Document Calendar Date
75210241...............................859889179......................................5/9/2013
75210241...............................9647889180....................................5/11/2013
81106197...............................9653785136...................................5/12/2013

The code for the above is this one :


SELECT  DISTINCT ['Direct_VPA invoice numbers$'].[Sales Order Identifier],['Direct_VPA invoice numbers$'].[Billing Document Identifier],
['Direct_VPA invoice numbers$'].[Billing Document Calendar Date]
FROM ['Direct_VPA invoice numbers$']




Basically an SO might contain different Billing Documents , if that's the case ,I'll need to concatenate that SO into one single row

I'm trying to change my data to look like this:

Sales Order Identifier...........Billing Document Identifier..............Billing Document Calendar Date
75210241......................... 859889179 , 9647889180..................5/9/2013, 5/11/2013
81106197................................9653785136...................................5/12/2013

So far I've tried some variations of the next code but I keep getting an error :

SELECT DISTINCT
['Direct_VPA invoice numbers$'].[Sales Order Identifier]
, STUFF((
SELECT N', ' + CAST(['Direct_VPA invoice numbers$'].[Billing Document Identifier] AS VARCHAR(255))
FROM ['Direct_VPA invoice numbers$'] f2
WHERE f1.['Direct_VPA invoice numbers$'].[Sales Order Identifier] = f2.['Direct_VPA invoice numbers$'].[Sales Order Identifier]
FOR XML PATH (''), TYPE), 1, 2, '') AS FileNameString
FROM ['Direct_VPA invoice numbers$'] f1



Error "IErrorInfo.GetDescription failed with E_FAIL(0x80004005)."

Any light here would be much appreciated
Jeff Moden
Jeff Moden
SSC Guru
SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)

Group: General Forum Members
Points: 85859 Visits: 41091
Please see the following article for one pretty easy method.
http://www.sqlservercentral.com/articles/comma+separated+list/71700/

--Jeff Moden

RBAR is pronounced ree-bar and is a Modenism for Row-By-Agonizing-Row.
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
If you think its expensive to hire a professional to do the job, wait until you hire an amateur. -- Red Adair

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search