Select query to xls output

  • Hi Team,

    using below script to export the select statement result to .xls

    declare @sql varchar(8000)

    select @sql = 'bcp "select * from Databases..Table" queryout c:\bcp\Tom.xls -c -t, -T -S' + @@servername

    exec master..xp_cmdshell @sql

    But result is not exporting in seperate tabs, all 4 column details are exporting in single cell.

    how to export the data in columns to seperate tabs in excel.

    Please suggest

  • Minnu (4/21/2015)


    Hi Team,

    using below script to export the select statement result to .xls

    declare @sql varchar(8000)

    select @sql = 'bcp "select * from Databases..Table" queryout c:\bcp\Tom.xls -c -t, -T -S' + @@servername

    exec master..xp_cmdshell @sql

    But result is not exporting in seperate tabs, all 4 column details are exporting in single cell.

    how to export the data in columns to seperate tabs in excel.

    Please suggest

    Try outputting to a CSV file (tom.csv) and then opening that in Excel.


  • It's not BCP but with OPENROWSET you will able to export in various tabs in a xls; refer the following link for further detail

    http://www.sqlservercentral.com/Forums/Topic487837-19-1.aspx

    HTH

    ---------------------------------------------------
    "Thare are only 10 types of people in the world:
    Those who understand binary, and those who don't."

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

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