SQL Serlect - Result export to EXCEL

  • Hi Team,

    using below query to compare columns in two tables.

    SELECT

    Col1 = ISNULL(a.name,b.name),

    Col2 =

    CASE

    WHEN ISNULL(a.name,'') = '' THEN 'Table B'

    WHEN ISNULL(b.name,'') = '' THEN 'Table A'

    ELSE 'Table A & Table B'

    END

    FROM #tableA a

    FULL JOIN #tableB b

    ON a.name = b.name;

    How to export the result to EXCEL from SQL Server 2008 R2.

  • SSMSBoost[/url] is a free SSMS add-in that lets you export the query results to Excel easily.

    -- Gianluca Sartori

  • Is there any possibility to export from SSMS without addins.

  • Copy / paste or Import/Export wizard are two possibilities.

    -- Gianluca Sartori

  • From within Excel, you can also embed a Data Connection with your query in it. For example in Excel 2013, go to the Data tab and use the 'From Other Data Sources...' wizard to set this up. Select 'SQL' when you get to the Command Type menu choice.

    This is perhaps not what you meant by 'Export' but it is another way to get data into a spreadsheet. It does not require SSMS or any add-in. It may be a bit more convenient if you need to re-run the query often.

  • Do you need .xls file at client computer or at the sever?

    If it has to be a server side procedure i see two options.

    1. Use OPENROWSET.

    insert into OPENROWSET('Microsoft.ACE.OLEDB.12.0',

    'Excel 8.0;Database=D:\222\myFile.xls;',

    'SELECT [name], create_date FROM [MySheet$]')

    select [name], create_date

    from sys.all_views

    It requiers some preparations. Be also ready to read criptic error messages when debugging.

    2. Create an XML conforming to Office Open XML Formats https://technet.microsoft.com/en-us/library/cc179190.aspx

    and just save it to file. No preparations, and it is compatible with other office software.

  • If the result set isn't too large copy paste works fine.

  • "This is perhaps not what you meant by 'Export' but it is another way to get data into a spreadsheet. It does not require SSMS or any add-in. It may be a bit more convenient if you need to re-run the query often. "

    Minnu: as you give us little information about the purpose of your task I will continue on

    the quotation above.

    As your goal is to put information in Excel why not use the Tools in Excel. You don't have to struggle with T SQL. With PowerPivot you can connect to the database and use your question to fill a table in the PowerPivot database which you can use to present and analys information in Excel.

    Gosta M

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

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