Can I use SQL to build an Excel data table from other Excel files?











up vote
3
down vote

favorite
1












I know SQL well enough to perform basic queries and manipulate data split into multiple tables in a database. I know Excel 2007 a bit better and use it frequently to manage my mechanical engineering projects.



Sometimes in Excel I want to manipulate data from multiple spreadsheets and combine into one table - a task well-suited for a SQL query. Usually when I encounter problems like this, my immediate reaction is to start building a query in my head. Unfortunately, a lot of times SQL queries do not easily translate to Excel functions and this stops me in my tracks.



Is it possible to utilize SQL for these functions within Excel?










share|improve this question




























    up vote
    3
    down vote

    favorite
    1












    I know SQL well enough to perform basic queries and manipulate data split into multiple tables in a database. I know Excel 2007 a bit better and use it frequently to manage my mechanical engineering projects.



    Sometimes in Excel I want to manipulate data from multiple spreadsheets and combine into one table - a task well-suited for a SQL query. Usually when I encounter problems like this, my immediate reaction is to start building a query in my head. Unfortunately, a lot of times SQL queries do not easily translate to Excel functions and this stops me in my tracks.



    Is it possible to utilize SQL for these functions within Excel?










    share|improve this question


























      up vote
      3
      down vote

      favorite
      1









      up vote
      3
      down vote

      favorite
      1






      1





      I know SQL well enough to perform basic queries and manipulate data split into multiple tables in a database. I know Excel 2007 a bit better and use it frequently to manage my mechanical engineering projects.



      Sometimes in Excel I want to manipulate data from multiple spreadsheets and combine into one table - a task well-suited for a SQL query. Usually when I encounter problems like this, my immediate reaction is to start building a query in my head. Unfortunately, a lot of times SQL queries do not easily translate to Excel functions and this stops me in my tracks.



      Is it possible to utilize SQL for these functions within Excel?










      share|improve this question















      I know SQL well enough to perform basic queries and manipulate data split into multiple tables in a database. I know Excel 2007 a bit better and use it frequently to manage my mechanical engineering projects.



      Sometimes in Excel I want to manipulate data from multiple spreadsheets and combine into one table - a task well-suited for a SQL query. Usually when I encounter problems like this, my immediate reaction is to start building a query in my head. Unfortunately, a lot of times SQL queries do not easily translate to Excel functions and this stops me in my tracks.



      Is it possible to utilize SQL for these functions within Excel?







      microsoft-excel microsoft-excel-2007 database sql






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 22 '10 at 19:28









      BinaryMisfit

      18.7k106276




      18.7k106276










      asked Nov 22 '10 at 19:23









      NoCatharsis

      1,512103655




      1,512103655






















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          4
          down vote



          accepted










          You can use ADO with Excel VBA. For example:



          Dim cn As ADODB.Connection
          Dim rs As ADODB.Recordset

          ''This is just a convenient name to test, it would probably be
          ''better to use the full file name eg C:DocsXL.xls
          strFile = Workbooks(1).FullName

          ''For ACE see: http://www.connectionstrings.com/excel-2007
          strCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strFile _
          & ";Extended Properties=""Excel 8.0;HDR=Yes;IMEX=1"";"

          Set cn = CreateObject("ADODB.Connection")
          Set rs = CreateObject("ADODB.Recordset")

          cn.Open strCon

          ''Pick one:
          strSQL = "SELECT * FROM DataTable" ''Named range
          strSQL = "SELECT * FROM [Sheet1$A1:E346]" ''Range
          strSQL = "SELECT * FROM [Sheet1$]" ''All the data in a sheet
          strSQL = "SELECT * FROM [Excel 8.0;HDR=YES;IMEX=1;" _
          & "database=C:DocsLTD.xls].[Sheet1$]" ''Refer to second workbook

          rs.Open strSQL, cn

          ''Write a recordset to a sheet
          Worksheets("Sheet3").Cells(2, 1).CopyFromRecordset rs


          The query can use anything acceptable in Jet SQL:



          Fundamental Microsoft Jet SQL for Access 2000
          Intermediate Microsoft Jet SQL for Access 2000
          Advanced Microsoft Jet SQL for Access 2000



          You will find quite a bit more on: https://stackoverflow.com/, including adding to MS Access, SQL Server, MySQL and so forth.






          share|improve this answer























          • Thanks a lot - wow this is a little more over my head than I thought. I'll check out some solutions on S.O. and maybe even look into just transferring my data straight over into a small database.
            – NoCatharsis
            Nov 23 '10 at 17:10


















          up vote
          1
          down vote













          Your case is exactly like I had couple months ago. I also try to build SQL query in my head every time I need to do some manipulate with data in Excel. So, I have created a little Add-In called XLTools SQL Queries. Now I have published it on our website for others like you and me!



          It allows to build any SQL query against tables in Excel workbook(s) using embedded SQL editor and run it immediately with the option to put result on a new or any existing worksheet.



          It is a lot easier to use if you just need to create and run SQL query - no VBA, no complex manipulations with MS Query...



          Here is an example:



          XLTools SQL Queries - Query Builder






          share|improve this answer























            Your Answer








            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "3"
            };
            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%2fsuperuser.com%2fquestions%2f213851%2fcan-i-use-sql-to-build-an-excel-data-table-from-other-excel-files%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            4
            down vote



            accepted










            You can use ADO with Excel VBA. For example:



            Dim cn As ADODB.Connection
            Dim rs As ADODB.Recordset

            ''This is just a convenient name to test, it would probably be
            ''better to use the full file name eg C:DocsXL.xls
            strFile = Workbooks(1).FullName

            ''For ACE see: http://www.connectionstrings.com/excel-2007
            strCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strFile _
            & ";Extended Properties=""Excel 8.0;HDR=Yes;IMEX=1"";"

            Set cn = CreateObject("ADODB.Connection")
            Set rs = CreateObject("ADODB.Recordset")

            cn.Open strCon

            ''Pick one:
            strSQL = "SELECT * FROM DataTable" ''Named range
            strSQL = "SELECT * FROM [Sheet1$A1:E346]" ''Range
            strSQL = "SELECT * FROM [Sheet1$]" ''All the data in a sheet
            strSQL = "SELECT * FROM [Excel 8.0;HDR=YES;IMEX=1;" _
            & "database=C:DocsLTD.xls].[Sheet1$]" ''Refer to second workbook

            rs.Open strSQL, cn

            ''Write a recordset to a sheet
            Worksheets("Sheet3").Cells(2, 1).CopyFromRecordset rs


            The query can use anything acceptable in Jet SQL:



            Fundamental Microsoft Jet SQL for Access 2000
            Intermediate Microsoft Jet SQL for Access 2000
            Advanced Microsoft Jet SQL for Access 2000



            You will find quite a bit more on: https://stackoverflow.com/, including adding to MS Access, SQL Server, MySQL and so forth.






            share|improve this answer























            • Thanks a lot - wow this is a little more over my head than I thought. I'll check out some solutions on S.O. and maybe even look into just transferring my data straight over into a small database.
              – NoCatharsis
              Nov 23 '10 at 17:10















            up vote
            4
            down vote



            accepted










            You can use ADO with Excel VBA. For example:



            Dim cn As ADODB.Connection
            Dim rs As ADODB.Recordset

            ''This is just a convenient name to test, it would probably be
            ''better to use the full file name eg C:DocsXL.xls
            strFile = Workbooks(1).FullName

            ''For ACE see: http://www.connectionstrings.com/excel-2007
            strCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strFile _
            & ";Extended Properties=""Excel 8.0;HDR=Yes;IMEX=1"";"

            Set cn = CreateObject("ADODB.Connection")
            Set rs = CreateObject("ADODB.Recordset")

            cn.Open strCon

            ''Pick one:
            strSQL = "SELECT * FROM DataTable" ''Named range
            strSQL = "SELECT * FROM [Sheet1$A1:E346]" ''Range
            strSQL = "SELECT * FROM [Sheet1$]" ''All the data in a sheet
            strSQL = "SELECT * FROM [Excel 8.0;HDR=YES;IMEX=1;" _
            & "database=C:DocsLTD.xls].[Sheet1$]" ''Refer to second workbook

            rs.Open strSQL, cn

            ''Write a recordset to a sheet
            Worksheets("Sheet3").Cells(2, 1).CopyFromRecordset rs


            The query can use anything acceptable in Jet SQL:



            Fundamental Microsoft Jet SQL for Access 2000
            Intermediate Microsoft Jet SQL for Access 2000
            Advanced Microsoft Jet SQL for Access 2000



            You will find quite a bit more on: https://stackoverflow.com/, including adding to MS Access, SQL Server, MySQL and so forth.






            share|improve this answer























            • Thanks a lot - wow this is a little more over my head than I thought. I'll check out some solutions on S.O. and maybe even look into just transferring my data straight over into a small database.
              – NoCatharsis
              Nov 23 '10 at 17:10













            up vote
            4
            down vote



            accepted







            up vote
            4
            down vote



            accepted






            You can use ADO with Excel VBA. For example:



            Dim cn As ADODB.Connection
            Dim rs As ADODB.Recordset

            ''This is just a convenient name to test, it would probably be
            ''better to use the full file name eg C:DocsXL.xls
            strFile = Workbooks(1).FullName

            ''For ACE see: http://www.connectionstrings.com/excel-2007
            strCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strFile _
            & ";Extended Properties=""Excel 8.0;HDR=Yes;IMEX=1"";"

            Set cn = CreateObject("ADODB.Connection")
            Set rs = CreateObject("ADODB.Recordset")

            cn.Open strCon

            ''Pick one:
            strSQL = "SELECT * FROM DataTable" ''Named range
            strSQL = "SELECT * FROM [Sheet1$A1:E346]" ''Range
            strSQL = "SELECT * FROM [Sheet1$]" ''All the data in a sheet
            strSQL = "SELECT * FROM [Excel 8.0;HDR=YES;IMEX=1;" _
            & "database=C:DocsLTD.xls].[Sheet1$]" ''Refer to second workbook

            rs.Open strSQL, cn

            ''Write a recordset to a sheet
            Worksheets("Sheet3").Cells(2, 1).CopyFromRecordset rs


            The query can use anything acceptable in Jet SQL:



            Fundamental Microsoft Jet SQL for Access 2000
            Intermediate Microsoft Jet SQL for Access 2000
            Advanced Microsoft Jet SQL for Access 2000



            You will find quite a bit more on: https://stackoverflow.com/, including adding to MS Access, SQL Server, MySQL and so forth.






            share|improve this answer














            You can use ADO with Excel VBA. For example:



            Dim cn As ADODB.Connection
            Dim rs As ADODB.Recordset

            ''This is just a convenient name to test, it would probably be
            ''better to use the full file name eg C:DocsXL.xls
            strFile = Workbooks(1).FullName

            ''For ACE see: http://www.connectionstrings.com/excel-2007
            strCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strFile _
            & ";Extended Properties=""Excel 8.0;HDR=Yes;IMEX=1"";"

            Set cn = CreateObject("ADODB.Connection")
            Set rs = CreateObject("ADODB.Recordset")

            cn.Open strCon

            ''Pick one:
            strSQL = "SELECT * FROM DataTable" ''Named range
            strSQL = "SELECT * FROM [Sheet1$A1:E346]" ''Range
            strSQL = "SELECT * FROM [Sheet1$]" ''All the data in a sheet
            strSQL = "SELECT * FROM [Excel 8.0;HDR=YES;IMEX=1;" _
            & "database=C:DocsLTD.xls].[Sheet1$]" ''Refer to second workbook

            rs.Open strSQL, cn

            ''Write a recordset to a sheet
            Worksheets("Sheet3").Cells(2, 1).CopyFromRecordset rs


            The query can use anything acceptable in Jet SQL:



            Fundamental Microsoft Jet SQL for Access 2000
            Intermediate Microsoft Jet SQL for Access 2000
            Advanced Microsoft Jet SQL for Access 2000



            You will find quite a bit more on: https://stackoverflow.com/, including adding to MS Access, SQL Server, MySQL and so forth.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 19 at 3:28









            Pang

            535610




            535610










            answered Nov 23 '10 at 0:57









            Remou

            28819




            28819












            • Thanks a lot - wow this is a little more over my head than I thought. I'll check out some solutions on S.O. and maybe even look into just transferring my data straight over into a small database.
              – NoCatharsis
              Nov 23 '10 at 17:10


















            • Thanks a lot - wow this is a little more over my head than I thought. I'll check out some solutions on S.O. and maybe even look into just transferring my data straight over into a small database.
              – NoCatharsis
              Nov 23 '10 at 17:10
















            Thanks a lot - wow this is a little more over my head than I thought. I'll check out some solutions on S.O. and maybe even look into just transferring my data straight over into a small database.
            – NoCatharsis
            Nov 23 '10 at 17:10




            Thanks a lot - wow this is a little more over my head than I thought. I'll check out some solutions on S.O. and maybe even look into just transferring my data straight over into a small database.
            – NoCatharsis
            Nov 23 '10 at 17:10












            up vote
            1
            down vote













            Your case is exactly like I had couple months ago. I also try to build SQL query in my head every time I need to do some manipulate with data in Excel. So, I have created a little Add-In called XLTools SQL Queries. Now I have published it on our website for others like you and me!



            It allows to build any SQL query against tables in Excel workbook(s) using embedded SQL editor and run it immediately with the option to put result on a new or any existing worksheet.



            It is a lot easier to use if you just need to create and run SQL query - no VBA, no complex manipulations with MS Query...



            Here is an example:



            XLTools SQL Queries - Query Builder






            share|improve this answer



























              up vote
              1
              down vote













              Your case is exactly like I had couple months ago. I also try to build SQL query in my head every time I need to do some manipulate with data in Excel. So, I have created a little Add-In called XLTools SQL Queries. Now I have published it on our website for others like you and me!



              It allows to build any SQL query against tables in Excel workbook(s) using embedded SQL editor and run it immediately with the option to put result on a new or any existing worksheet.



              It is a lot easier to use if you just need to create and run SQL query - no VBA, no complex manipulations with MS Query...



              Here is an example:



              XLTools SQL Queries - Query Builder






              share|improve this answer

























                up vote
                1
                down vote










                up vote
                1
                down vote









                Your case is exactly like I had couple months ago. I also try to build SQL query in my head every time I need to do some manipulate with data in Excel. So, I have created a little Add-In called XLTools SQL Queries. Now I have published it on our website for others like you and me!



                It allows to build any SQL query against tables in Excel workbook(s) using embedded SQL editor and run it immediately with the option to put result on a new or any existing worksheet.



                It is a lot easier to use if you just need to create and run SQL query - no VBA, no complex manipulations with MS Query...



                Here is an example:



                XLTools SQL Queries - Query Builder






                share|improve this answer














                Your case is exactly like I had couple months ago. I also try to build SQL query in my head every time I need to do some manipulate with data in Excel. So, I have created a little Add-In called XLTools SQL Queries. Now I have published it on our website for others like you and me!



                It allows to build any SQL query against tables in Excel workbook(s) using embedded SQL editor and run it immediately with the option to put result on a new or any existing worksheet.



                It is a lot easier to use if you just need to create and run SQL query - no VBA, no complex manipulations with MS Query...



                Here is an example:



                XLTools SQL Queries - Query Builder







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Jul 4 '14 at 21:40

























                answered Jul 4 '14 at 21:32









                Peter Liapin

                213




                213






























                     

                    draft saved


                    draft discarded



















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f213851%2fcan-i-use-sql-to-build-an-excel-data-table-from-other-excel-files%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

                    Index of /

                    Tribalistas

                    Listed building