Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Concatenate Rows (PowerPivot) Expand / Collapse
Author
Message
Posted Wednesday, October 30, 2013 3:26 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, October 30, 2013 5:11 PM
Points: 5, 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



Post #1509956
Posted Wednesday, October 30, 2013 6:30 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 8:27 AM
Points: 35,349, Visits: 31,889
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."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #1509990
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse