Ian Sherwood
Ian Sherwood

Reputation: 36

Automatically export SQL query to a csv or txt file

I'm currently using SSRS to export reports. However my client would like to have a url to download or file dynamically produced possibly on a schedule or on command.

What would be the best way of doing this without trying to force SSRS to do more than it can?

Is there a simple way. I am new to SQL.

Upvotes: 0

Views: 2542

Answers (2)

K Richard
K Richard

Reputation: 1984

Why not use the subscription and delivery services within SSRS (http://technet.microsoft.com/en-us/library/ms159762.aspx)? The nice thing about this is it will allow you to choose a number of convenient render options. You can have it email or send to a shared file location. If the client is asking for this to be produced on demand, then wouldn't the export option within SSRS be sufficient?

Upvotes: 1

Shreyos Adikari
Shreyos Adikari

Reputation: 12744

You can use this query :

SQLCMD -S YourSQLServer -d YourDatabase -U YourUserName -P
YourPassword -Q “Your Query” -s “,” -o “C:\Yourfilename.csv”

Now you can go to your file location and open the file and you will see that new csv file created there. When you open the csv file you will notice the results of the query.

Check http://blog.sqlauthority.com/2013/03/05/sql-server-exporting-query-results-to-csv-using-sqlcmd/ this for more details.

Upvotes: 0

Related Questions