Randy Minder
Randy Minder

Reputation: 48482

Extra row in Pivot Output

I have a simple table that looks as follows:

enter image description here

I'm executing the following query:

SELECT 
    DeviceId,
    [UCL],
    [LCL]
FROM dbo.BreweryTemperatureSetpoint
PIVOT
(
    SUM(SetpointValue) FOR SetpointName IN ([UCL], [LCL])
) AS PVT

The output looks like this:

enter image description here

What I would like is a single row that looks like this:

Prototype1, 24, 21.75

There is something about Pivot I don't quite understand since I would have thought my query would produce the desired output, but it isn't.

Upvotes: 1

Views: 17

Answers (1)

John Cappelletti
John Cappelletti

Reputation: 81990

Limit the fields in the "Source" to what is needed. XAxis, YAxis and Value

SELECT *
FROM (
        Select DeviceId,SetpointValue,SetpointName
         FROM dbo.BreweryTemperatureSetpoint
     )  A
PIVOT
(
    SUM(SetpointValue) FOR SetpointName IN ([UCL], [LCL])
) AS PVT

Upvotes: 2

Related Questions