I have the following SQL query that gives me the data I need. However, I need to transpose the rows into columns.
Ie.
Instead of using union to put them all together I need each query as a separate column. One row per order number.
select * from
(
select ROW_NUMBER() OVER(PARTITION BY DHH_ORDER_NO ORDER BY DHH_DELIVERYNOTE_NO DESC) AS 'RowNum'
,CAST(DHH_ORDER_NO AS float) AS DHH_ORDER_NO
, DHH_DELIVERYNOTE_NO from SYS_DEL_HISTORY_HEADER
where DHH_ORIGIN in ('SOO') and DHH_ORDER_NO = '7904'
) Delivery1
where RowNum = 1
--
(select * from
(
select ROW_NUMBER() OVER(PARTITION BY DHH_ORDER_NO ORDER BY DHH_DELIVERYNOTE_NO DESC) AS 'RowNum'
,CAST(DHH_ORDER_NO AS float) AS DHH_ORDER_NO
, DHH_DELIVERYNOTE_NO from SYS_DEL_HISTORY_HEADER
where DHH_ORIGIN in ('SOO') and DHH_ORDER_NO = '7904'
) Delivery2
where RowNum = 2)
--
(select * from
(
select ROW_NUMBER() OVER(PARTITION BY DHH_ORDER_NO ORDER BY DHH_DELIVERYNOTE_NO DESC) AS 'RowNum'
,CAST(DHH_ORDER_NO AS float) AS DHH_ORDER_NO
, DHH_DELIVERYNOTE_NO from SYS_DEL_HISTORY_HEADER
where DHH_ORIGIN in ('SOO') and DHH_ORDER_NO = '7904'
) Delivery3
where RowNum = 3)
--
(select * from
(
select ROW_NUMBER() OVER(PARTITION BY DHH_ORDER_NO ORDER BY DHH_DELIVERYNOTE_NO DESC) AS 'RowNum'
,CAST(DHH_ORDER_NO AS float) AS DHH_ORDER_NO
, DHH_DELIVERYNOTE_NO from SYS_DEL_HISTORY_HEADER
where DHH_ORIGIN in ('SOO') and DHH_ORDER_NO = '7904'
) Delivery4
where RowNum = 4)
--
(select * from
(
select ROW_NUMBER() OVER(PARTITION BY DHH_ORDER_NO ORDER BY DHH_DELIVERYNOTE_NO DESC) AS 'RowNum'
,CAST(DHH_ORDER_NO AS float) AS DHH_ORDER_NO
, DHH_DELIVERYNOTE_NO from SYS_DEL_HISTORY_HEADER
where DHH_ORIGIN in ('SOO') and DHH_ORDER_NO = '7904'
) Delivery5
where RowNum = 5)
--
(select * from
(
select ROW_NUMBER() OVER(PARTITION BY DHH_ORDER_NO ORDER BY DHH_DELIVERYNOTE_NO DESC) AS 'RowNum'
,CAST(DHH_ORDER_NO AS float) AS DHH_ORDER_NO
, DHH_DELIVERYNOTE_NO from SYS_DEL_HISTORY_HEADER
where DHH_ORIGIN in ('SOO') and DHH_ORDER_NO = '7904'
) Delivery6
where RowNum = 6)
Ie.
Instead of using union to put them all together I need each query as a separate column. One row per order number.
select * from
(
select ROW_NUMBER() OVER(PARTITION BY DHH_ORDER_NO ORDER BY DHH_DELIVERYNOTE_NO DESC) AS 'RowNum'
,CAST(DHH_ORDER_NO AS float) AS DHH_ORDER_NO
, DHH_DELIVERYNOTE_NO from SYS_DEL_HISTORY_HEADER
where DHH_ORIGIN in ('SOO') and DHH_ORDER_NO = '7904'
) Delivery1
where RowNum = 1
--
(select * from
(
select ROW_NUMBER() OVER(PARTITION BY DHH_ORDER_NO ORDER BY DHH_DELIVERYNOTE_NO DESC) AS 'RowNum'
,CAST(DHH_ORDER_NO AS float) AS DHH_ORDER_NO
, DHH_DELIVERYNOTE_NO from SYS_DEL_HISTORY_HEADER
where DHH_ORIGIN in ('SOO') and DHH_ORDER_NO = '7904'
) Delivery2
where RowNum = 2)
--
(select * from
(
select ROW_NUMBER() OVER(PARTITION BY DHH_ORDER_NO ORDER BY DHH_DELIVERYNOTE_NO DESC) AS 'RowNum'
,CAST(DHH_ORDER_NO AS float) AS DHH_ORDER_NO
, DHH_DELIVERYNOTE_NO from SYS_DEL_HISTORY_HEADER
where DHH_ORIGIN in ('SOO') and DHH_ORDER_NO = '7904'
) Delivery3
where RowNum = 3)
--
(select * from
(
select ROW_NUMBER() OVER(PARTITION BY DHH_ORDER_NO ORDER BY DHH_DELIVERYNOTE_NO DESC) AS 'RowNum'
,CAST(DHH_ORDER_NO AS float) AS DHH_ORDER_NO
, DHH_DELIVERYNOTE_NO from SYS_DEL_HISTORY_HEADER
where DHH_ORIGIN in ('SOO') and DHH_ORDER_NO = '7904'
) Delivery4
where RowNum = 4)
--
(select * from
(
select ROW_NUMBER() OVER(PARTITION BY DHH_ORDER_NO ORDER BY DHH_DELIVERYNOTE_NO DESC) AS 'RowNum'
,CAST(DHH_ORDER_NO AS float) AS DHH_ORDER_NO
, DHH_DELIVERYNOTE_NO from SYS_DEL_HISTORY_HEADER
where DHH_ORIGIN in ('SOO') and DHH_ORDER_NO = '7904'
) Delivery5
where RowNum = 5)
--
(select * from
(
select ROW_NUMBER() OVER(PARTITION BY DHH_ORDER_NO ORDER BY DHH_DELIVERYNOTE_NO DESC) AS 'RowNum'
,CAST(DHH_ORDER_NO AS float) AS DHH_ORDER_NO
, DHH_DELIVERYNOTE_NO from SYS_DEL_HISTORY_HEADER
where DHH_ORIGIN in ('SOO') and DHH_ORDER_NO = '7904'
) Delivery6
where RowNum = 6)