0

I have two table having data like below:

            SELECT *
              FROM [dbo].[TestTable_1]
            ID  Value
            ----------
            1   gjha      
            2   dc        
            3   d         
            4   ds        
            5   dg        
            6   hn    

2nd table:

            SELECT *
              FROM [dbo].[TestTable_2]
            Value
            -----
            jklsa
            dfv
            b
            grt
            trj
            h
            muik
            rg
            kuu
            wd
            gb
            nm
            wef

I'm fetching the data in SSRS report as below:
enter image description here

Question is:

How can I maintain the table size same? That is, if small table in SSRS report has 6 records (which is in this case), the bigger one should adjust same size as small and the extra (/more) records that are coming in the large table should shift to right.

Here is the expected output from SSRS

            Value           Value
            --------  -----------------
            gjha      jklsa |muik | wef
            dc        dfv   |rg   |
            d         b     |kuu  |
            ds        grt   |wd   |
            dg        trj   |gb   |
            hn        h     |nm   |

Note: The above details are just example, however, the number of records are really dynamic.

Cœur
  • 37,241
  • 25
  • 195
  • 267
AskMe
  • 2,495
  • 8
  • 49
  • 102

2 Answers2

0

This is not a full answer as it's just what came to mind and is completely untested.

First thing is to search SO for ways to create a multi-column table, there are plenty of answers already so I won't explain in detail here. They usually involve adding RowNumber to each row which you can then use to calculate a matrix row and matrix column number, the column number can be used in a matrix as the column group. (e.g. if the row limit is 6 and the row number is 14, that will have a final row number of 2 (14 mod 6 = 2) and a column number of 3 as Floor(14/6)+1 = 3.

Next, create dataset that just gets the highest row count from each of your tables. Something like

DECLARE @a int
DECLARE @b int
SELECT @a = COUNT(*) FROM myTableA
SELECT @b = COUNT(*) FROM myTableA

SELECT CASE WHEN @a<=@b THEN @a ELSE @b END AS maxRows

Now you have the size of the smallest table, you can pass that as a parameter to the proc that gets the actual data from the two tables (this would be 6 in our example above)

Alan Schofield
  • 19,839
  • 3
  • 22
  • 35
  • Would you please suggest any link or tutorial to refer please? note: my data set is different and there are actually 3 columns these 3 colums are coming from 3 different data set. – AskMe May 28 '19 at 08:47
0

I just answered a similar question here: https://stackoverflow.com/a/56350614/2033717

You can adapt this solution to your situation by replacing the 3 in the expressions with:

=Floor(Count(Fields!ColumnName.Value, "Dataset1") / Count(Fields!ColumnName.Value, "Dataset1"))

In other words, you're determining how many columns you need. And then grouping each row of the dataset into rows and columns of the matrix. This will work if you know the second table can be bigger than the first, but I'm not sure if it will work both ways without some additional conditions on the expressions.

StevenWhite
  • 5,907
  • 3
  • 21
  • 46