Может ли кто-нибудь помочь отладить мой запрос, он должен вращать строки, но значения возвращают только нули.
SELECT
blockID
--, Atype
--,alarmTypeID
, Alarm1Type = MAX([AlarmType1])
, Manufacturer1Name = MAX([Manufacturer1])
, Alarm2Type = MAX([AlarmType2])
, Manufacturer2Name = MAX([Manufacturer2])
, Alarm3Type = MAX([AlarmType3])
, Manufacturer3Name = MAX([Manufacturer3])
, Alarm4Type = MAX([AlarmType4])
, Manufacturer4Name = MAX([Manufacturer4])
FROM (
SELECT
BlockAlarms.blockID
,BlockAlarms.alarmTypeID
, AlarmType.alarmType as Atype
, BlockAlarms.manufacturerID
,AlarmType.alarmType + CAST(DENSE_RANK() OVER (PARTITION BY BlockAlarms.blockID ORDER BY AlarmType.alarmType ASC) AS NVARCHAR) AS [AlarmType]
,'Manufact' + CAST(DENSE_RANK() OVER (PARTITION BY BlockAlarms.blockID ORDER BY AlarmType.alarmType ASC) AS NVARCHAR) AS [Manufacturer]
FROM BlockAlarms INNER JOIN
AlarmType ON BlockAlarms.alarmTypeID = AlarmType.alarmTypeID
) AS query
PIVOT (MAX(alarmTypeID)
FOR [AlarmType] IN ([AlarmType1],[AlarmType2],[AlarmType3], [AlarmType4])) AS Pivot1
PIVOT (MAX(manufacturerID)
FOR [Manufacturer] IN ([Manufacturer1],[Manufacturer2],[Manufacturer3],[Manufacturer4])) AS Pivot2
GROUP BY
blockID
--, Atype
ORDER BY blockID
Первый столбец возвращает номер блока, как и ожидалось.
Данные, которые он должен поворачивать:
blockAlarmID blockID alarmTypeID manufacturerID alarmType
251 731 4 Break Glass
252 731 9 Dry Riser
253 731 11 Emergency Lights
254 731 6 Fire Panel
255 731 2 Smoke Alarm
256 731 5 Smoke Detectors
257 731 7 Sounders
283 731 4 Eurotech EURV-MCPI-IP24 Break Glass
284 731 10 Rocburn AOV
285 731 11 Lumineux 400775 Emergency Lights
286 731 6 Eurotech 600-100 basement Fire Panel
287 731 2 Aico El146 Smoke Alarm
288 731 5 Rockburn series 65 Smoke Detectors
289 731 7 EURV-WSR basement Sounders
Любая помощь приветствуется.