November 9, 2009 at 3:21 am
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.
November 9, 2009 at 5:16 am
You may try using the openrowset() function .
http://technet.microsoft.com/en-us/library/ms190312.aspx
An example is provided in the blog below:
November 10, 2009 at 6:15 am
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.
November 10, 2009 at 3:30 pm
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"
November 10, 2009 at 4:01 pm
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.
November 10, 2009 at 4:31 pm
You could also run the query through SQLCMD and save it to an output text file.
Joie Andrew
"Since 1982"
November 12, 2009 at 6:51 am
Yes i am Using SSMS....
Thanks for you support.
November 12, 2009 at 11:05 am
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