SSRS Report from a PIVOT query with unknown number of columns











up vote
0
down vote

favorite












I have a PIVOT query that is returning an unknown number of dynamic columns. So the query will return something like



ID | Col1 | Col2 | ..... | ColN



ID is the only static column and the rest are all dynamic. The number and the names of the columns are unknown.



How can I write a report in SSRS that can handle this? Any tips and direction will be appreciated.



Thanks.










share|improve this question


























    up vote
    0
    down vote

    favorite












    I have a PIVOT query that is returning an unknown number of dynamic columns. So the query will return something like



    ID | Col1 | Col2 | ..... | ColN



    ID is the only static column and the rest are all dynamic. The number and the names of the columns are unknown.



    How can I write a report in SSRS that can handle this? Any tips and direction will be appreciated.



    Thanks.










    share|improve this question
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I have a PIVOT query that is returning an unknown number of dynamic columns. So the query will return something like



      ID | Col1 | Col2 | ..... | ColN



      ID is the only static column and the rest are all dynamic. The number and the names of the columns are unknown.



      How can I write a report in SSRS that can handle this? Any tips and direction will be appreciated.



      Thanks.










      share|improve this question













      I have a PIVOT query that is returning an unknown number of dynamic columns. So the query will return something like



      ID | Col1 | Col2 | ..... | ColN



      ID is the only static column and the rest are all dynamic. The number and the names of the columns are unknown.



      How can I write a report in SSRS that can handle this? Any tips and direction will be appreciated.



      Thanks.







      sql tsql reporting-services pivot






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 14 hours ago









      JackSmith

      114




      114
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote



          accepted










          SSRS will not be able to handle your pivot table because the columns are not known at design time. SSRS has feature called Matrix that will handle the pivot a run time based off run time data if your design time structure is static.



          ID | ColumnName | Value
          ------------------------
          1 | Colu1 | Value1
          1 | Colu2 | Value2
          2 | Colu2 | Value2


          I would recommend that you return detail rows from TSQL and allow SSRS to handle the pivot. This will allow for one stored procedure to be used for multiple SSRS reports and aggregations instead of the single aggregation provide by PIVOT.



          To save on duplicate processing, Matrix will also handle the sorting so no need to sort inside of TSQL.



          Reference: Create a Matrix






          share|improve this answer























          • So currently my query returns data in the form I listed above. You want me to write a query in the format - ID | Column | Value and then use a matrix in SSRS?
            – JackSmith
            14 hours ago










          • SSRS does a wonderful job at runtime pivot tables. Yes, I would write the query with the above structure and use a matrix.
            – rschoenbach
            14 hours ago










          • Ok I wrote the query to get the data in the following format. However I need one little change. The query is select distinct pApps.ApplicationID, ppl.LastName As ColName, isnull(ev.AnswerNumeric, 0) as ColValue from pApps inner join ev on pApps.SomeColumn = ev.SomeColumn inner join ppl on pApps.SomeColumn = ppl.SomeColumn Order By ApplicationID I need to add a total column as well. The data is coming out as ApplicationID | ColName | ColValue 12 | A | 5 12| B | 9 14 | A | 12 14 | B | 3 I need to add a total for each application that is the sum of A & B
            – JackSmith
            13 hours ago












          • @JackSmith SSRS Matrix has the ability to create a total row for you. Reference
            – rschoenbach
            13 hours ago










          • Ok great thanks
            – JackSmith
            13 hours ago











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














           

          draft saved


          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53416269%2fssrs-report-from-a-pivot-query-with-unknown-number-of-columns%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          0
          down vote



          accepted










          SSRS will not be able to handle your pivot table because the columns are not known at design time. SSRS has feature called Matrix that will handle the pivot a run time based off run time data if your design time structure is static.



          ID | ColumnName | Value
          ------------------------
          1 | Colu1 | Value1
          1 | Colu2 | Value2
          2 | Colu2 | Value2


          I would recommend that you return detail rows from TSQL and allow SSRS to handle the pivot. This will allow for one stored procedure to be used for multiple SSRS reports and aggregations instead of the single aggregation provide by PIVOT.



          To save on duplicate processing, Matrix will also handle the sorting so no need to sort inside of TSQL.



          Reference: Create a Matrix






          share|improve this answer























          • So currently my query returns data in the form I listed above. You want me to write a query in the format - ID | Column | Value and then use a matrix in SSRS?
            – JackSmith
            14 hours ago










          • SSRS does a wonderful job at runtime pivot tables. Yes, I would write the query with the above structure and use a matrix.
            – rschoenbach
            14 hours ago










          • Ok I wrote the query to get the data in the following format. However I need one little change. The query is select distinct pApps.ApplicationID, ppl.LastName As ColName, isnull(ev.AnswerNumeric, 0) as ColValue from pApps inner join ev on pApps.SomeColumn = ev.SomeColumn inner join ppl on pApps.SomeColumn = ppl.SomeColumn Order By ApplicationID I need to add a total column as well. The data is coming out as ApplicationID | ColName | ColValue 12 | A | 5 12| B | 9 14 | A | 12 14 | B | 3 I need to add a total for each application that is the sum of A & B
            – JackSmith
            13 hours ago












          • @JackSmith SSRS Matrix has the ability to create a total row for you. Reference
            – rschoenbach
            13 hours ago










          • Ok great thanks
            – JackSmith
            13 hours ago















          up vote
          0
          down vote



          accepted










          SSRS will not be able to handle your pivot table because the columns are not known at design time. SSRS has feature called Matrix that will handle the pivot a run time based off run time data if your design time structure is static.



          ID | ColumnName | Value
          ------------------------
          1 | Colu1 | Value1
          1 | Colu2 | Value2
          2 | Colu2 | Value2


          I would recommend that you return detail rows from TSQL and allow SSRS to handle the pivot. This will allow for one stored procedure to be used for multiple SSRS reports and aggregations instead of the single aggregation provide by PIVOT.



          To save on duplicate processing, Matrix will also handle the sorting so no need to sort inside of TSQL.



          Reference: Create a Matrix






          share|improve this answer























          • So currently my query returns data in the form I listed above. You want me to write a query in the format - ID | Column | Value and then use a matrix in SSRS?
            – JackSmith
            14 hours ago










          • SSRS does a wonderful job at runtime pivot tables. Yes, I would write the query with the above structure and use a matrix.
            – rschoenbach
            14 hours ago










          • Ok I wrote the query to get the data in the following format. However I need one little change. The query is select distinct pApps.ApplicationID, ppl.LastName As ColName, isnull(ev.AnswerNumeric, 0) as ColValue from pApps inner join ev on pApps.SomeColumn = ev.SomeColumn inner join ppl on pApps.SomeColumn = ppl.SomeColumn Order By ApplicationID I need to add a total column as well. The data is coming out as ApplicationID | ColName | ColValue 12 | A | 5 12| B | 9 14 | A | 12 14 | B | 3 I need to add a total for each application that is the sum of A & B
            – JackSmith
            13 hours ago












          • @JackSmith SSRS Matrix has the ability to create a total row for you. Reference
            – rschoenbach
            13 hours ago










          • Ok great thanks
            – JackSmith
            13 hours ago













          up vote
          0
          down vote



          accepted







          up vote
          0
          down vote



          accepted






          SSRS will not be able to handle your pivot table because the columns are not known at design time. SSRS has feature called Matrix that will handle the pivot a run time based off run time data if your design time structure is static.



          ID | ColumnName | Value
          ------------------------
          1 | Colu1 | Value1
          1 | Colu2 | Value2
          2 | Colu2 | Value2


          I would recommend that you return detail rows from TSQL and allow SSRS to handle the pivot. This will allow for one stored procedure to be used for multiple SSRS reports and aggregations instead of the single aggregation provide by PIVOT.



          To save on duplicate processing, Matrix will also handle the sorting so no need to sort inside of TSQL.



          Reference: Create a Matrix






          share|improve this answer














          SSRS will not be able to handle your pivot table because the columns are not known at design time. SSRS has feature called Matrix that will handle the pivot a run time based off run time data if your design time structure is static.



          ID | ColumnName | Value
          ------------------------
          1 | Colu1 | Value1
          1 | Colu2 | Value2
          2 | Colu2 | Value2


          I would recommend that you return detail rows from TSQL and allow SSRS to handle the pivot. This will allow for one stored procedure to be used for multiple SSRS reports and aggregations instead of the single aggregation provide by PIVOT.



          To save on duplicate processing, Matrix will also handle the sorting so no need to sort inside of TSQL.



          Reference: Create a Matrix







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 14 hours ago

























          answered 14 hours ago









          rschoenbach

          713




          713












          • So currently my query returns data in the form I listed above. You want me to write a query in the format - ID | Column | Value and then use a matrix in SSRS?
            – JackSmith
            14 hours ago










          • SSRS does a wonderful job at runtime pivot tables. Yes, I would write the query with the above structure and use a matrix.
            – rschoenbach
            14 hours ago










          • Ok I wrote the query to get the data in the following format. However I need one little change. The query is select distinct pApps.ApplicationID, ppl.LastName As ColName, isnull(ev.AnswerNumeric, 0) as ColValue from pApps inner join ev on pApps.SomeColumn = ev.SomeColumn inner join ppl on pApps.SomeColumn = ppl.SomeColumn Order By ApplicationID I need to add a total column as well. The data is coming out as ApplicationID | ColName | ColValue 12 | A | 5 12| B | 9 14 | A | 12 14 | B | 3 I need to add a total for each application that is the sum of A & B
            – JackSmith
            13 hours ago












          • @JackSmith SSRS Matrix has the ability to create a total row for you. Reference
            – rschoenbach
            13 hours ago










          • Ok great thanks
            – JackSmith
            13 hours ago


















          • So currently my query returns data in the form I listed above. You want me to write a query in the format - ID | Column | Value and then use a matrix in SSRS?
            – JackSmith
            14 hours ago










          • SSRS does a wonderful job at runtime pivot tables. Yes, I would write the query with the above structure and use a matrix.
            – rschoenbach
            14 hours ago










          • Ok I wrote the query to get the data in the following format. However I need one little change. The query is select distinct pApps.ApplicationID, ppl.LastName As ColName, isnull(ev.AnswerNumeric, 0) as ColValue from pApps inner join ev on pApps.SomeColumn = ev.SomeColumn inner join ppl on pApps.SomeColumn = ppl.SomeColumn Order By ApplicationID I need to add a total column as well. The data is coming out as ApplicationID | ColName | ColValue 12 | A | 5 12| B | 9 14 | A | 12 14 | B | 3 I need to add a total for each application that is the sum of A & B
            – JackSmith
            13 hours ago












          • @JackSmith SSRS Matrix has the ability to create a total row for you. Reference
            – rschoenbach
            13 hours ago










          • Ok great thanks
            – JackSmith
            13 hours ago
















          So currently my query returns data in the form I listed above. You want me to write a query in the format - ID | Column | Value and then use a matrix in SSRS?
          – JackSmith
          14 hours ago




          So currently my query returns data in the form I listed above. You want me to write a query in the format - ID | Column | Value and then use a matrix in SSRS?
          – JackSmith
          14 hours ago












          SSRS does a wonderful job at runtime pivot tables. Yes, I would write the query with the above structure and use a matrix.
          – rschoenbach
          14 hours ago




          SSRS does a wonderful job at runtime pivot tables. Yes, I would write the query with the above structure and use a matrix.
          – rschoenbach
          14 hours ago












          Ok I wrote the query to get the data in the following format. However I need one little change. The query is select distinct pApps.ApplicationID, ppl.LastName As ColName, isnull(ev.AnswerNumeric, 0) as ColValue from pApps inner join ev on pApps.SomeColumn = ev.SomeColumn inner join ppl on pApps.SomeColumn = ppl.SomeColumn Order By ApplicationID I need to add a total column as well. The data is coming out as ApplicationID | ColName | ColValue 12 | A | 5 12| B | 9 14 | A | 12 14 | B | 3 I need to add a total for each application that is the sum of A & B
          – JackSmith
          13 hours ago






          Ok I wrote the query to get the data in the following format. However I need one little change. The query is select distinct pApps.ApplicationID, ppl.LastName As ColName, isnull(ev.AnswerNumeric, 0) as ColValue from pApps inner join ev on pApps.SomeColumn = ev.SomeColumn inner join ppl on pApps.SomeColumn = ppl.SomeColumn Order By ApplicationID I need to add a total column as well. The data is coming out as ApplicationID | ColName | ColValue 12 | A | 5 12| B | 9 14 | A | 12 14 | B | 3 I need to add a total for each application that is the sum of A & B
          – JackSmith
          13 hours ago














          @JackSmith SSRS Matrix has the ability to create a total row for you. Reference
          – rschoenbach
          13 hours ago




          @JackSmith SSRS Matrix has the ability to create a total row for you. Reference
          – rschoenbach
          13 hours ago












          Ok great thanks
          – JackSmith
          13 hours ago




          Ok great thanks
          – JackSmith
          13 hours ago


















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53416269%2fssrs-report-from-a-pivot-query-with-unknown-number-of-columns%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Trompette piccolo

          Slow SSRS Report in dynamic grouping and multiple parameters

          Simon Yates (cyclisme)