July 6, 2017 at 2:30 am
Hi guys,
I am looking for a query that can switch my rows and columns in the table below :
The final result will look like that :
Many Thanks
July 6, 2017 at 3:23 am
First unpivot, then pivot:
IF OBJECT_ID('tempdb..#test') IS NOT NULL
DROP TABLE #test;
CREATE TABLE #test(
populationtypedescription varchar(10)
,totalload int
,totalfirstload int
);
INSERT INTO #test VALUES ('pop2',20,17);
INSERT INTO #test VALUES ('pop3',3,2);
INSERT INTO #test VALUES ('pop4',4,4);
SELECT *
FROM #test
UNPIVOT (value FOR col IN (totalload, totalfirstload)) AS u
PIVOT (MIN(value) FOR populationtypedescription IN ([pop2],[pop3],[pop4])) AS p
-- Gianluca Sartori
July 6, 2017 at 4:00 am
July 6, 2017 at 4:44 am
spaghettidba - Thursday, July 6, 2017 3:23 AMOK , so i have another issue
I tried to add another field which is defined as DATE type
and the vdate field creates a new conflict
Any suggestions how to convert it to an int?
Thanks again
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply