Hi for my ssrs report i am using a matrix to display data row as a two column list and I am using the following expression in order to group the row;
=ceiling(rownumber(nothing) / 2) and
the following expression to group column;
=ceiling(rownumber(nothing) mod 2)
it is working correctly however i would like results to be display alphabetical order going vertical instead of horizontal.
Like.
Record a Record d
Record b Record e
Record c Record f
Instead of
Record a Record b
Record c Record d
Record e Record f
i have order by in my sql query
any suggestions on how to achieve this?
You can modify your sql for this. The hack below could be used if you do not want to use multiple columns.
DECLARE @T TABLE
(
TableID INT,
Value1 NVARCHAR(20),
ShouldBe INT
)
INSERT INTO @T (TableID,Value1,ShouldBe)
VALUES
(1,'A',1),
(2,'B',3),
(3,'C',5),
(4,'D',2),
(5,'E',4),
(6,'F',6),
(7,'A',1),
(8,'B',3),
(9,'C',5),
(10,'D',2),
(11,'E',4),
(12,'F',6),
(13,'A',1)
DECLARE @NumberOfRowsPerPage INT = 3
DECLARE @NumberOfColumns INT = 2
SELECT PageNumber,Value1
FROM
(
SELECT ColumnOrder=ROW_NUMBER() OVER(PARTITION BY PageNumber,ColumnTile ORDER BY TableID),*
FROM
(
SELECT ColumnTile=NTILE(@NumberOfColumns) OVER(PARTITION BY PageNumber ORDER BY TableID),*
FROM
(
SELECT PageNumber=( (DataRowNumber -1) / (@NumberOfRowsPerPage * @NumberOfColumns )) + 1, *
FROM
(
SELECT DataRowNumber=ROW_NUMBER() OVER( ORDER BY TableID) ,*
FROM @T
)AS A
)AS B
)AS C
)AS D
ORDER BY
PageNumber,ColumnOrder,DataRowNumber
The query will produce the following output based on the RowsPerPage and NumberOfColumns.
Page Value
1 A
1 D
1 B
1 E
1 C
1 F
2 A
2 D
2 B
2 E
2 C
2 F
3 A
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.