您可以在 SSRS 数据集查询中使用表变量,就像在我的代码中添加所需的“空”记录以将组页脚保持在固定位置(示例使用 pubs 数据库):
声明 @NumberOfLines INT
声明 @RowsToProcess INT
声明 @CurrentRow INT
声明@CurRow INT
声明 @cntMax INT
声明 @NumberOfRecords INT
声明@SelectedType char(12)
DECLARE @varTable TABLE (# int, type char(12), ord int)
DECLARE @table1 TABLE (type char(12), title varchar(80), ord int )
DECLARE @table2 TABLE (type char(12), title varchar(80), ord int )
插入@varTable
SELECT count(type) as '#', type, count(type) FROM Titles GROUP BY type ORDER BY type
从@varTable 中选择@cntMax = max(#)
INSERT into @table1 (type, title, ord) SELECT type, N'', 1 FROM title
INSERT into @table2 (type, title, ord) SELECT type, title, 1 FROM title
设置@CurrentRow = 0
SET @SelectedType = N''
SET @NumberOfLines = @RowsPerPage
从@varTable 中选择@RowsToProcess = COUNT(*)
而@CurrentRow < @RowsToProcess
开始设置@CurrentRow
= @CurrentRow + 1
SELECT TOP 1 @NumberOfRecords = ord, @SelectedType = type
FROM @varTable WHERE type > @SelectedType
SET @CurRow = 0
WHILE @CurRow < (@NumberOfLines - @NumberOfRecords % @NumberOfLines) % @NumberOfLines
BEGIN
SET @CurRow = @CurRow + 1
INSERT into @table2 (type, title, ord)
SELECT type, '' , 2
FROM @varTable WHERE type = @SelectedType
END
END
SELECT type, title FROM @table2 ORDER BY type ASC, ord ASC, title ASC