I have table as below after pivoting,
Order_ID Report1_ID Report2_ID Report3_ID Order_1 OR_1 null null Order_2 null OR_2 null Order_3 null null OR_3 Order_4 OR_4 null null Order_5 null OR_5 null Order_6 null null OR_6 Order_7 OR_7 null null Order_8 null OR_8 null Order_9 null null OR_9
I need like,
Serial_NO Report1_ID Report2_ID Report3_ID 1 OR_1 OR_2 OR_3 2 OR_4 OR_5 OR_6 3 OR_7 OR_8 OR_9
I need to remove all the null values and list like above table. My Query as below,
SELECT *
FROM (
select
ORDER_ID,
'Report' + cast((dense_rank() OVER ( ORDER BY order_number) - 1) % 3 + 1) as varchar)) + '_ID' ORDER_S_NO
from OrderTable
)main
PIVOT ( max(ORDER_ID) FOR ORDER_S_NO IN (Report1_ID,Report2_ID,Report3_ID) ) AS pivotTable;
Thanks in advance.