Output query result to a specific cell in preformatted excel file

  • Dear All,

    How can i output query result to a specific cell in a preformatted excel file. Thanks.

  • Sounds like something you should be doing within Excel with VBA, so an Excel site may be a better place to ask the question.

  • Jack Corbett (2/6/2009)


    Sounds like something you should be doing within Excel with VBA, so an Excel site may be a better place to ask the question.

    Actually Im not. Maybe my question is not specific enough. Sorry for my english. I would like to rephrase my question.. How can I output my SQL Query to an excel file or in a specific cell of an excel file.. thanks for the reply

  • What are you using to generate the results (SSMS, Reporting Services, A custom application)?

  • Im a newbie to T-SQL and a little programming knowledge. What can you suggest? Do you have a sample script just to give me an idea on how to start it?

  • Since I don't really know what you need to do and why I can't really make any suggestions. If you have SQL Server other than express edition you have Reporting Services included and this is a GUI report writer that will allow you to export results to Excel, so it may be the best option.

    Or you can use VBA in Excel to connect to SQL Server and return the results to Excel, but, as I mentioned, that is really a question for Excel gurus not SQL gurus.

  • TomYum - Openrowset is a quick method to export to Excel but please note the requirements carefully

    /*This is an example of how to output to Excel.

    Requirements:

    This willl not work with Excel 2007, but will with earlier versions of Excel

    Spread sheet must exist on the SERVER

    In row 1 must be the names of the table fields being exported

    Database=F:\TestData\Book2.xls' - is the full path and name of the existing Excel work book

    FROM [Sheet1$]') designates which sheet of the work book will be utilized. (The $ sign is required)

    SELECT * FROM your tables name - in the example it is "Keywords"

    */

    INSERT INTO OPENROWSET('Microsoft.Jet.OLEDB.4.0', 'Excel 8.0;Database=F:\TestData\Book2.xls',

    'SELECT * FROM [Sheet1$]')

    SELECT * FROM Keywords

    If everything seems to be going well, you have obviously overlooked something.

    Ron

    Please help us, help you -before posting a question please read[/url]
    Before posting a performance problem please read[/url]

  • Jack Corbett (2/6/2009)


    Since I don't really know what you need to do and why I can't really make any suggestions. If you have SQL Server other than express edition you have Reporting Services included and this is a GUI report writer that will allow you to export results to Excel, so it may be the best option.

    Or you can use VBA in Excel to connect to SQL Server and return the results to Excel, but, as I mentioned, that is really a question for Excel gurus not SQL gurus.

    Thank you Jack...

Viewing 8 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic. Login to reply