sdamiano
asked on
How to collapse rows returned from SQL SELECT into one?
Hello,
the following query joins two tables and produces the following results:
SELECT DT1.Name, DT1.SectorID, DT1.ExposureBiasID, DT2.AssetClassID
FROM DT_Strategy DT1, DT_StrategyAssetClass DT2
WHERE DT1.ID = DT2.StrategyID AND DT1.ID = 1
-------------------------- ---------- ---------- ---------- ----------
Relative Value Equity Long 4 1 1
Relative Value Equity Long 4 1 2
Relative Value Equity Long 4 1 3
-------------------------- ---------- ---------- ---------- ----------
All the resulting rows are equal except for the value in the last column. I would like to collapse them into one row as follows:
-------------------------- ---------- ---------- ---------- ---------- ----
Relative Value Equity Long 4 1 1,2,3
-------------------------- ---------- ---------- ---------- ---------- ----
Is this possible in SQL? Or do I need to do it programatically?
Thanks,
Stefano
the following query joins two tables and produces the following results:
SELECT DT1.Name, DT1.SectorID, DT1.ExposureBiasID, DT2.AssetClassID
FROM DT_Strategy DT1, DT_StrategyAssetClass DT2
WHERE DT1.ID = DT2.StrategyID AND DT1.ID = 1
--------------------------
Relative Value Equity Long 4 1 1
Relative Value Equity Long 4 1 2
Relative Value Equity Long 4 1 3
--------------------------
All the resulting rows are equal except for the value in the last column. I would like to collapse them into one row as follows:
--------------------------
Relative Value Equity Long 4 1 1,2,3
--------------------------
Is this possible in SQL? Or do I need to do it programatically?
Thanks,
Stefano
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
it works perfectly!
Thanks,
Stefano