SQL Data in Excel

Posted on 2007-07-21
Last Modified: 2016-08-29
Hi Everyone-

I am using excel(2003 and 2007 versions) to upload to and display informtion from a SQL(2005) table.  The SQL stores budget information.  There are two main identifers in the table: 1) a Service Code and 2) a specific Project Code.  When the person uses the excel file, they upload information regarding a specific project and they go to another sheet that shows totals from a number of different projects that correspond to that Service.  Right now to display the overall budget info, I have it set up like this:
     1) I excel bring in the entire SQL table (which has about 100 rows/60 columns of data
     2) Based on a project code field that that it is in a excel cell as well as the SQL table, I have a number     of "SumIfs" formulas to populate certain cells in excel that display the overal totals for different areas for that service based on the individual projects.

Needless to say, the excel file is getting very large.  Is there a way to have these "sumifs"/queries occur on the SQL side so the only information brought it is based on the "Service" code that is selected by the user.  Also, say I want cell C6 on the "Budget Summary" sheet to display the grand total for the Service from the Office Expenses column in the SQL table, is that possible?

I hope I made sense.  Thank you for your help, this is all new to me.  
Question by:bclivell
    LVL 92

    Accepted Solution

    Hello bclivell,

    Possibly.  For example, SQL views could be created to perform some of the calculations
    on the server side, and/or you could have stored procedures calculate the results, and
    use ADO to retrieve those results.  Without knowing more about your specific
    situation, it is hard to get more concrete than that.

    Also, you may be able to use a PivotTable on the Excel side instead of SUMIF().


    LVL 17

    Expert Comment

    Why don't you do the Sum within the SQL....

    Select Sum(MyField1) As Total1, Sum(MyField2) As Total2, Sum(MyField1) + Sum(MyField2) As TotalAll Form [MyTable] Where [Project = 'MyProject';

    Author Comment

    Thank you for the quick response.  Please let me know what other information I could provide.  I am not sure how to create SQL views to make the caculations.  Thank you!

    Thank you for your quick response as well.  Where and how would I do what you are refering to.  Also, how would I display that info the a specific cell in Excel?  Thank you!
    LVL 92

    Expert Comment

    by:Patrick Matthews

    Well, it would be useful to see a small subset of the raw data and
    the calcs you are looking to do.  Please upload a sample file to an
    accessible web site, and come back here to post a link to the file.

    If you do not have your own web space, you can use  Please be advised that you will have to
    zip your file(s) before uploading if you use that service.



    Author Comment

    Patrick-  I have uploaded the files.  Here are the links

    View all files for Question ID: 22711552

    Direct link to your file

    Some cells will have "ref" errors in them, b/c I had to strip it down for privacy reasons.  The bugdet summary is where I am trying to display the info.  The SQL Data tab is where I have the table that is displayed to the SQL table.  All data in there is dummy data.  Thank you so much!!

    Author Comment

    My apologies, I did not expain the budget summary page well enough.  

    The "Client" section will be based on another SQL table that I have not gotten to yet so it is empty.  Under that, there are the "Office Expenses", "Vendor Expenses" and Team Fees section.  The column that is "overall" is where I am trying to fill in the grand totals for the budget info.  I hope this helps.  Thank you again!!
    LVL 17

    Assisted Solution

    If you have microsoft access, make links to your database, crerate the query you need using access.  Then click view sql and you can copy/paste into your application.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
    You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
    This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now