私のコードのように、SSRS データセット クエリでテーブル変数を使用できます。このコードでは、グループ フッターを固定位置に保持するために必要な「空の」レコードを追加しています (サンプルでは、pubs データベースを使用しています)。
DECLARE @NumberOfLines INT
DECLARE @RowsToProcess INT
DECLARE @CurrentRow INT
DECLARE @CurRow INT
DECLARE @cntMax INT
DECLARE @NumberOfRecords INT
DECLARE @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 titles
INSERT into @table2 (type, title, ord) SELECT type, title, 1 FROM titles
SET @CurrentRow = 0
SET @SelectedType = N''
SET @NumberOfLines = @RowsPerPage
SELECT @RowsToProcess = COUNT(*) from @varTable
WHILE @CurrentRow < @RowsToProcess
BEGIN
SET @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