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

后端 未结 3 859
滥情空心
滥情空心 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 22:53

    Use the 'Report' menu in Visual Studio and select 'Report Properties'. You can set columns in the 'Layout' tab.

    Try this msdn article about newsletter-style reports for more details: http://msdn.microsoft.com/en-us/library/ms159107.aspx

    This method does have a limitation though so in some cases it might not be applicable:

    Only PDF and Image renderers support newsletter-style reports.

    EDIT: So one approach is to use multiple tablix with a filter that checks RowNumber and accordingly displays particular records in each table.

    The other way is called Newsletter-style report (link). This formatting is retained only when report is exported as PDF or Image. It can be previewed only when you select 'Print Layout' on the Preview tab in Visual Studio. Here is an example:

    1. Create a new report with the foll. dataset: SELECT ID,NAME FROM TABLENAME
    2. Add a new table to the report and select the ID and Name as columns
    3. Click on the tablix and press F4 to edit the tablix properties. In the properties window, change the Size - set the width to 2in
    4. Click on the report area outside the report page boundary and press F4 to edit the report properties. In the properties window, change the Column value to 3, and column spacing value to 0.1
    5. On the report scroll to the right hand side, you will notice that there are 2 new columns (so totally 3 columns on the report - because you selected 3 in step 4 above). Now click on the margin at the start of the column 2 and pull it further to the left to bring it as close to the column 1. This is only to reduce the need for huge page size.
    6. Right click on the report area outside the report page boundary and select Report Properties. Change the Page Size - Set the width to 10in
    7. Preview the report. Now select the 'Print Layout' tab to see the result. This formatting is retained only when report is exported as PDF or Image.

    As noted in points 5 and 6 - since the report body flows into multiple columns, you must ensure that the page size is at-least equal to -> ([Original report body size times the number of columns] + all the column spacing values). Otherwise it will look messy.

    0 讨论(0)
  • 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

    0 讨论(0)
  • 2020-11-27 23:13

    For Horizontal layout of labels...

    One choice is to use the columns property on the report or body elements. This doesn't always display correctly On reportviewer. I've noticed that even if it displays correctly on your IDE and when you export to PDF. In the report viewer it will display only one column. Also it snakes the labels top to bottom then left to right.

    One choice is to use a matrix and group on every 3 rows (if you want 3 columns).

    This one is a little complicated.

    My solution of choice is to put 3 vertical lists on the page. put the same label in each list. Return the row number in your dataset. Then just filter each list on modulo 3

    For example

    Result set

    RIndex Fname
    1 abe
    2 burt
    3 fred
    4 george
    

    Filter expressions

    list 1 -> =Fields!RIndex.Value mod 3 = =1
    list 2 -> =Fields!RIndex.Value mod 3 = =2
    list 3 -> =Fields!RIndex.Value mod 3 = =0
    

    Result

    Abe Burt Fred 
    George 
    
    0 讨论(0)
提交回复
热议问题