Results 1 to 6 of 6

Thread: Export Query To Excel

  1. #1

    Thread Starter
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,826

    Export Query To Excel

    Does anyone know if there's a method to export a query into an excel spreadsheet?

    I've looked around, but I can't seem to find any solution that works.

    I'm just getting the data like so:

    SQL Code:
    1. SELECT tbl_HPMRBInventory.ID, tbl_HPMRBInventory.RecvDate, tbl_HPMRBInventory.CSO_N, tbl_Commodity.CommodityType, tbl_HPOEMPN.Part_Number, tbl_HPOEMPN.Platform, tbl_HPMRBInventory.Site_ID, tbl_HPMRBInventory.GP_TransferError, tbl_HPOEMPN.OEM_Name
    2. FROM ((tbl_HPMRBInventory LEFT JOIN tbl_HPOEMPN ON tbl_HPMRBInventory.PN_ID = tbl_HPOEMPN.ID) LEFT JOIN tbl_Commodity ON tbl_HPOEMPN.Commodity_Type = tbl_Commodity.ID) LEFT JOIN tbl_Location ON tbl_HPOEMPN.LocationID = tbl_Location.LocationID
    3. WHERE (((tbl_HPMRBInventory.GP_TransferError) Like 'Invalid Part in GP*') AND ((tbl_HPMRBInventory.GP_Transfer)=0 Or (tbl_HPMRBInventory.GP_Transfer) Is Null))
    4. ORDER BY tbl_HPMRBInventory.RecvDate;

    So I was hoping I could do the same, but automatically export it all to a spreadsheet.
    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: Export Query To Excel

    Who would run the query? Excel can't, SQL Server can't, Access might come pretty close, and .NET can....with a few steps along the way. I have a class over in the .NET CodeBank that I wrote to export datatables and datareaders. That might not apply for you, though.
    My usual boring signature: Nothing

  3. #3
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: Export Query To Excel

    I think SQL Server can do it all by itself if you create a DTS (Data Transformation Services) package that sends the query results to an Excel file, looks like an easy one (1 step or 2). Then a job can execute the package either directly or scheduled.

  4. #4

    Thread Starter
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,826

    Re: Export Query To Excel

    Quote Originally Posted by Shaggy Hiker View Post
    Who would run the query? Excel can't, SQL Server can't, Access might come pretty close, and .NET can....with a few steps along the way. I have a class over in the .NET CodeBank that I wrote to export datatables and datareaders. That might not apply for you, though.
    I was planning on executing the query and everything through a scheduled job. I've setup the email portion through the job. Now I just need to export the data and attach the sheet.

    Quote Originally Posted by jcis View Post
    I think SQL Server can do it all by itself if you create a DTS (Data Transformation Services) package that sends the query results to an Excel file, looks like an easy one (1 step or 2). Then a job can execute the package either directly or scheduled.
    Everything that I've looked up so far suggests that DTS is depreciated. I'll keep looking though.
    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

  5. #5
    Wall Poster TysonLPrice's Avatar
    Join Date
    Sep 2002
    Location
    Columbus, Ohio
    Posts
    3,969

    Re: Export Query To Excel

    I'm not sure exactly what you want but you can put the query into Excel and run it when you open the spreadsheet. The user refreshes the data when it comes up. Look at the menu item "From Other Sources" in version 2007. I think it was "External data sources" in 2003.

    Basically you set up a connection.
    Step through selecting your tables etc.
    Edit the query Excel created replacing it with yours.
    And go

    http://excelusergroup.org/blogs/nick...rnal-data.aspx
    Last edited by TysonLPrice; Oct 25th, 2011 at 10:22 AM.

  6. #6
    PowerPoster abhijit's Avatar
    Join Date
    Jun 1999
    Location
    Chit Chat Forum.
    Posts
    3,228

    Re: Export Query To Excel

    In 2010, the option is under the Data tab captioned as "connections".
    You can use this to link your sheet to an external data source.

    However, I am guessing that's not what you are looking for.
    Everything that has a computer in will fail. Everything in your life, from a watch to a car to, you know, a radio, to an iPhone, it will fail if it has a computer in it. They should kill the people who made those things.- 'Woz'
    save a blobFileStreamDataTable To Text Filemy blog

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width