Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 horizontal tables in ssrs

Author  Topic 

fredmitch
Starting Member

1 Post

Posted - 2011-11-28 : 03:58:17
Hi guys and girls

I presently have a table for which the data is displayed as the following:
G P A
1:04 |15 34 |5.1
01:04 |150 9 |13.5
01:04 |25 14 |3.5
01:04 |250 7 |17.5
01:04 |35 13 |4.55
01:04 |45 13 |5.85
01:04 |55 23 |12.65
01:04 |550 |4 22
01:10 |125 |2 2.5
01:10 |125 |2 2.5
01:25 |75 |2 1.5
A |HWH 75 | 9 6.75
B |55 |8 4.4
C |attrak 55 |5 2.75

Is there some clever person among you that can display the data like the following: Next to each other grouped as rows of fours(4).

G P A G P A G P A G P A
01:04 |15 34 |5.1 01:04 |35 13 |4.55 01:10 |125 |2 2.5 01:25 |75 | 1.5
01:04 |150 9 |13.5 01:04 |45 13 |5.85 01:10 |125 |2 2.5 A |HWH 75 |9.75
01:04 |25 14 |3.5 01:04 |55 23 |12.65 01:10 |75 |2 1.5 B |55 |8 4.4
01:04 |250 7 |17.5 01:04 |550 |4 22 01:25 |125 |2 2.5 C |attrak 55 |5 2.75
...


Kind regards and thank you for your assistance.

Fred

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-11-28 : 04:43:49
do like


SELECT MAX( CASE WHEN (Rn-1)/4 = 0 THEN G ELSE NULL END) AS G1,
MAX( CASE WHEN (Rn-1)/4 = 0 THEN P ELSE NULL END) AS P1,
MAX( CASE WHEN (Rn-1)/4 = 0 THEN A ELSE NULL END) AS A1,
MAX( CASE WHEN (Rn-1)/4 = 1 THEN G ELSE NULL END) AS G2,
MAX( CASE WHEN (Rn-1)/4 = 1 THEN P ELSE NULL END) AS P2,
MAX( CASE WHEN (Rn-1)/4 = 1 THEN A ELSE NULL END) AS A2,
MAX( CASE WHEN (Rn-1)/4 = 2 THEN G ELSE NULL END) AS G3,
MAX( CASE WHEN (Rn-1)/4 = 2 THEN P ELSE NULL END) AS P3,
MAX( CASE WHEN (Rn-1)/4 = 2 THEN A ELSE NULL END) AS A3,
....
MAX( CASE WHEN (Rn-1)/4 = 3 THEN P ELSE NULL END) AS P4,
MAX( CASE WHEN (Rn-1)/4 = 3 THEN A ELSE NULL END) AS A4
FROM
(
SELECT *,ROW_NUMBER() OVER (ORDER BY G) AS Rn
FROM table
)t
GROUP BY (Rn-1)%4


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -