4 Replies Latest reply on Jun 14, 2013 4:51 AM by michael.mcveigh

    How can I apply the UNION ALL SQL script to an Excel file that has more than 2 sheets?

    michael.mcveigh

      http://kb.tableausoftware.com/articles/knowledgebase/union-related-data-across-multiple-excel-tabs?keywords=create%20union

       

      The above link reference how a UNION ALL can be accomplished for a workbook with 2 sheets but I need to join a file that has 5 sheets.  I have attached the excel file for reference. 

        • 1. Re: How can I apply the UNION ALL SQL script to an Excel file that has more than 2 sheets?
          Alex Kerin

          Just stick another union on and change the syntax as required - is that not working?

          • 2. Re: How can I apply the UNION ALL SQL script to an Excel file that has more than 2 sheets?
            michael.mcveigh

            Since I'm not that familiar with sql, I'm not 100% sure how that would/should look. 

            • 3. Re: How can I apply the UNION ALL SQL script to an Excel file that has more than 2 sheets?
              Alex Kerin

              SELECT [Q1Bing$].[Account] AS [Account],

                [Q1Bing$].[Ad group] AS [Ad group],

                [Q1Bing$].[Avg# CPC] AS [Avg# CPC],

                [Q1Bing$].[Avg# position] AS [Avg# position],

                [Q1Bing$].[Campaign] AS [Campaign],

                [Q1Bing$].[Channel] AS [Channel],

                [Q1Bing$].[Clicks] AS [Clicks],

                [Q1Bing$].[Cost] AS [Cost],

                [Q1Bing$].[CTR] AS [CTR],

                [Q1Bing$].[Day] AS [Day],

                [Q1Bing$].[Destination URL] AS [Destination URL],

                [Q1Bing$].[Impressions] AS [Impressions],

                [Q1Bing$].[Keyword] AS [Keyword]

              FROM [Q1Bing$]

              Union all

              SELECT [Q2Bing$].[Account] AS [Account],

                [Q2Bing$].[Ad group] AS [Ad group],

                [Q2Bing$].[Avg# CPC] AS [Avg# CPC],

                [Q2Bing$].[Avg# position] AS [Avg# position],

                [Q2Bing$].[Campaign] AS [Campaign],

                [Q2Bing$].[Channel] AS [Channel],

                [Q2Bing$].[Clicks] AS [Clicks],

                [Q2Bing$].[Cost] AS [Cost],

                [Q2Bing$].[CTR] AS [CTR],

                [Q2Bing$].[Day] AS [Day],

                [Q2Bing$].[Destination URL] AS [Destination URL],

                [Q2Bing$].[Impressions] AS [Impressions],

                [Q2Bing$].[Keyword] AS [Keyword]

              FROM [Q2Bing$]

              Union all

              SELECT [Q1Google$].[Account] AS [Account],

                [Q1Google$].[Ad group] AS [Ad group],

                [Q1Google$].[Avg# CPC] AS [Avg# CPC],

                [Q1Google$].[Avg# position] AS [Avg# position],

                [Q1Google$].[Campaign] AS [Campaign],

                [Q1Google$].[Channel] AS [Channel],

                [Q1Google$].[Clicks] AS [Clicks],

                [Q1Google$].[Cost] AS [Cost],

                [Q1Google$].[CTR] AS [CTR],

                [Q1Google$].[Day] AS [Day],

                [Q1Google$].[Destination URL] AS [Destination URL],

                [Q1Google$].[Impressions] AS [Impressions],

                [Q1Google$].[Keyword] AS [Keyword]

              FROM [Q1Google$]

              Union all

              SELECT [Q2Google$].[Account] AS [Account],

                [Q2Google$].[Ad group] AS [Ad group],

                [Q2Google$].[Avg# CPC] AS [Avg# CPC],

                [Q2Google$].[Avg# position] AS [Avg# position],

                [Q2Google$].[Campaign] AS [Campaign],

                [Q2Google$].[Channel] AS [Channel],

                [Q2Google$].[Clicks] AS [Clicks],

                [Q2Google$].[Cost] AS [Cost],

                [Q2Google$].[CTR] AS [CTR],

                [Q2Google$].[Day] AS [Day],

                [Q2Google$].[Destination URL] AS [Destination URL],

                [Q2Google$].[Impressions] AS [Impressions],

                [Q2Google$].[Keyword] AS [Keyword]

              FROM [Q2Google$]

              Union all

              SELECT [Yahoo$].[Account] AS [Account],

                [Yahoo$].[Ad group] AS [Ad group],

                [Yahoo$].[Avg# CPC] AS [Avg# CPC],

                [Yahoo$].[Avg# position] AS [Avg# position],

                [Yahoo$].[Campaign] AS [Campaign],

                [Yahoo$].[Channel] AS [Channel],

                [Yahoo$].[Clicks] AS [Clicks],

                [Yahoo$].[Cost] AS [Cost],

                [Yahoo$].[CTR] AS [CTR],

                [Yahoo$].[Day] AS [Day],

                [Yahoo$].[Destination URL] AS [Destination URL],

                [Yahoo$].[Impressions] AS [Impressions],

                [Yahoo$].[Keyword] AS [Keyword]

              FROM [Yahoo$]