Export data from SQL server 2000 to Excel

  • I want to do what I think should be a pretty easy task. I have a data set in SQL Server and I want to schedule a job to once a day push updated data to an Excel file I have on my server. I just need it to do a simple overwrite of the existing Excel file.

    I am using SQL Server 2005 client with a SQL Server 2000 server. I would rather not use DTS or SSIS because of that combo. I'm hoping there is some code I can put in a sproc that would get this job done and then I can just schedule the sproc as a job that runs nightly.

    TIA.

  • A warning up front, this solution is not good for security reasons because you have to have xp_cmdshell enabled, but if you already have that procedure enabled, you can do the following to bcp your data out:

    if you can't have xp_cmdshell enabled, you can schedule a windows task to bcp your data out.

    declare @bcp varchar(500)

    declare @select varchar(500)

    declare @path varchar(500)

    set @path = '"\\someserver\somefolder\somefile.xls"'

    SET @Select = '"SELECT * FROM tablename"'

    set @bcp = 'bcp ' + @select + ' queryout ' + @path + ' -S sqlservername -T -w'

    exec master..xp_cmdshell @bcp

  • Or...

    Create a view or a reporting table and use Excel's "Get External Data".

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 3 posts - 1 through 2 (of 2 total)

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