To display output in horizontal format. I have used cross apply in this example because in this case CROSS APPLY suits best. PIVOT is used when there is aggregation or to split column. UNPIVOT is used to change orientation but no. of columns need to be fixed. Even if you make it dynamic then also you can not use it in SSRS as SSRS need static dataset or rowset in old version with fixed number of columns predefined so that it could be saved with report definition. Link for script is mentioned below:
http://www.techsapphire.in/index/hori...