t-SQL to excel??

  • does anybody know how to convert results from t-sql to excel ??

     

    thanks

  • If you use QA, try Extras-> Options -> Results Tab. There you can specify, that you want a csv file as result that Excel can read.

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

  • If you're running the t-sql interactively in Query Manager you can also : view results in grid, then select the grid in the results pane, right-click in top corner of the grid and select copy then paste into Excel.

     

  • You might also look at using OPENDATSOURCE and simply inserting the data directly into an XLS file.

    To retrieve data...

    ---------------------------------------------------------------------------------------------------------------------------------

    -- TODO: Make sure to change the name/path of the spreadsheet below to reflect your machine.

    -- Also: Make sure the cells and Sheet name are the same as the select statement.

    -- Make sure the worksheet is shared out from within Excel. "Tools/Share Workbook..."

    ---------------------------------------------------------------------------------------------------------------------------------

    INSERT INTO #TempTable(<FieldList&gt

    SELECT <FieldList>

    FROM OPENDATASOURCE('Microsoft.Jet.OLEDB.4.0'

    ,'Data Source="<FilePath>.xls";User ID=Admin;Password=;Extended properties=Excel 8.0'

    )...Sheet1$

     

    -- To Insert Data

    INSERT INTO OPENDATASOURCE('Microsoft.Jet.OLEDB.4.0'

    ,'Data Source="<FilePath>.xls";User ID=Admin;Password=;Extended properties=Excel 8.0'

    )...Sheet1$(<FieldList&gt

    SELECT <FieldList>

    FROM Foo




    Gary Johnson
    Microsoft Natural Language Group
    DBA, Sr. DB Engineer

    This posting is provided "AS IS" with no warranties, and confers no rights. The opinions expressed in this post are my own and may not reflect that of my employer.

  • You can also place the query in a DTS Package and export it to Excel.


    Kindest Regards,

Viewing 5 posts - 1 through 4 (of 4 total)

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