How to export query result set into text/excel file?

  • How to export query result set into Text/Excel file using query or stored procedure?

    Say query is:

    Select * from sys.objects

    i want to save this result in text/excel file but through query.

  • While running query in above link i got following error.

    As i do not have administrator permission, can i still import data to excel sheet.

    Msg 15281, Level 16, State 1, Line 1

    SQL Server blocked access to STATEMENT 'OpenRowset/OpenDatasource' of component 'Ad Hoc Distributed Queries' because this component is turned off as part of the security configuration for this server. A system administrator can enable the use of 'Ad Hoc Distributed Queries' by using sp_configure. For more information about enabling 'Ad Hoc Distributed Queries', see "Surface Area Configuration" in SQL Server Books Online.

  • Are you using SSMS? In one of the menu options you should be able to direct your query output to a text file instead of a table.

    Joie Andrew
    "Since 1982"

  • alpeshgediya

    A system administrator can enable the use of 'Ad Hoc Distributed Queries' by using sp_configure. For more information about enabling 'Ad Hoc Distributed Queries', see "Surface Area Configuration" in SQL Server Books Online.

    There exists a reason for this ... it protects the Database against unwanted intrusion. Speak to your administrator to change your permissions. It is not wise to try to hack your way around this security provision.

    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]

  • You could also run the query through SQLCMD and save it to an output text file.

    Joie Andrew
    "Since 1982"

  • Yes i am Using SSMS....

    Thanks for you support.

  • So were you able to export your result set to a text file?

    Joie Andrew
    "Since 1982"

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

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