Monday, June 12, 2017

TSQL Pivot Example


DROP table #temp

create table #temp
(
  Rack varchar(200),
  Sensor varchar(200),
  Diff int
)

INSERT INTO #TEMP VALUES ('R1','TEMP',20)
INSERT INTO #TEMP VALUES ('R1','HUMID',20)
INSERT INTO #TEMP VALUES ('R2','TEMP',25)
INSERT INTO #TEMP VALUES ('R2','HUMID',22)
INSERT INTO #TEMP VALUES ('R3','TEMP',19)
INSERT INTO #TEMP VALUES ('R3','HUMID',10)

SELECT * FROM #temp

SELECT Rack, [TEMP],[HUMID]
FROM #temp
PIVOT (MAX(Diff) FOR Sensor IN ([TEMP],[HUMID])) AS X

No comments:

Post a Comment

Teams PowerShell

 The PowerShell helps to get quick meta data around Teams. Install-Module -Name MicrosoftTeams Connect-MicrosoftTeams Get-TeamAllChannel...