SSRS - How to build a simple multi-column report?

后端 未结 3 877
滥情空心
滥情空心 2020-11-27 22:46

I am using SQL Server 2008 and I want to show 1 single field from a table in multiple columns in the report. Just like if I were to print labels. How can I achieve this?

3条回答
  •  时光取名叫无心
    2020-11-27 23:07

    The method I use is a bit similar as what Vern suggested but differs enough to make it worth mentioning here.

    You can combine the ROW_NUMBER with the modulo (%) operator directly in the query to fabricate the column number in which the record should get displayed. Here's an example that generates one while taking a group into account:

    declare @numberOfColumns int = 4;
    
    select dpc.EnglishProductCategoryName, dp.ProductAlternateKey
        , (ROW_NUMBER() OVER (
            PARTITION BY dpc.EnglishProductCategoryName
            ORDER BY dp.ProductAlternateKey) + @numberOfColumns - 1) % @numberOfColumns + 1
        as DisplayColumn
    from dbo.DimProduct dp
    inner join dbo.DimProductSubcategory dps on dps.ProductSubcategoryKey = dp.ProductSubcategoryKey
    inner join dbo.DimProductCategory dpc on dpc.ProductCategoryKey = dps.ProductCategoryKey;
    

    To get this displayed I'm using nested tables which are then filtered on DisplayColumn.

    Have a read through following article for all the details: Creating Multiple-Column Reports

提交回复
热议问题