2

I require a table in report viewer to display a list of items pulled from the data source in a horizontal table.

The data source simply contains a list of strings contained in one SQL column.

Horizontal report table example

The tables I have tried so far only display it in a column.

Many thanks!

dynamicuser
  • 1,522
  • 3
  • 24
  • 52
  • 1
    See my answer in this duplicate question [SSRS report formatting a table to display data side by side](http://stackoverflow.com/questions/13721709/ssrs-report-formatting-a-table-to-display-data-side-by-side) – Chris Latta Apr 04 '13 at 08:20

1 Answers1

0

Here is what I understood of the requirements. Select from a list of items out of a table and report on them in a horizontal table. The values in the table may or may not be known.

In my example I am building a single string from a select producing a horizontal contiguous string from a list of items into a variable.

Then I build a dynamic SQL statement using the new variable and including a select from my desired table. In the dynamic SQL I do a simple replace so the PIVOT is formatted correctly. This resolves the problem of not knowing what data exists in the table before hand. Pivot requires you to label your columns using the field values within which can be a challenge if the values in the table are unknown or change constantly.

    DECLARE @FieldValueString VARCHAR(MAX)
        SELECT @FieldValueString = Coalesce(@FieldValueString + ',', '') + cast(ssctab as         varchar) from RA_sysScreen 

    PRINT @FieldValueString
    DECLARE @sql VARCHAR(MAX)
    SET @sql = 'SELECT * FROM
                (SELECT ssctab FROM [RA_sysScreen])qry
                PIVOT (MAX(ssctab) FOR ssctab in (['+REPLACE(@FieldValueString,',','],[')+']))         as pvt'
    print @sql
    EXEC(@sql)

Hope this helps. I look forward to seeing other answers on this one