August 2, 2019 at 1:14 pm
Hello All,
I'm trying to convert rows in table to columns as per the example i.e create one long string of data for every occurrence of ID column. Could anyone please help in achieving it in best way.
/** Build up a Table to work with. **/
DECLARE @T TABLE
(
ID INT NOT NULL
, hProp INT NOT NULL
, iDayOfMonth INT NOT NULL
, dblTargetPercent DECIMAL(6,4) NOT NULL
)
INSERT INTO @T
(ID, hProp, iDayOfMonth, dblTargetPercent)
VALUES (117,10,5,0.1400)
, (117, 10, 10, 0.0500)
, (117, 10, 15, 0.0100)
, (117, 10, 20, 0.0100)
, (118, 20, 20, 0.0100)
, (118, 30, 10, 0.0200)
SELECT * FROM @T;
Thanks and Regards,
Loki
August 2, 2019 at 5:16 pm
This is a duplicate post. Please use the following link to get to the duplicate and the answers. No posts on this link, please. It will only dilute the information about how to accomplish this task. Thanks, folks.
--Jeff Moden
Change is inevitable... Change for the better is not.
August 2, 2019 at 8:36 pm
Closing. Read answers here: https://www.sqlservercentral.com/forums/topic/convert-rows-into-columns-10
Viewing 3 posts - 1 through 2 (of 2 total)
The topic ‘Convert Rows into Columns’ is closed to new replies.