Solved

MS SQL export CSV & schedule It

Posted on 2016-10-25
9
52 Views
Last Modified: 2016-11-15
I just have a simple query that I want to run 5:00 pm PST Daily and export the data in csv format.
Can you show me the easiest way using SQL Server agent?
0
Comment
Question by:ITsolutionWizard
9 Comments
 
LVL 24

Expert Comment

by:Pawan Kumar
ID: 41859752
You can create a SQL Job with the below code..

DECLARE  @Command NVARCHAR(4000)=''
	
SET @Command = 'bcp " ' + 'SELECT CreditReport FROM [PAWAN].[ABCInvestment].data.CreditReport WHERE 1 = 1 ' + '"' + ' queryout "E:\Pawan' +  '.csv' + '"' + ' -T -N'
 
PRINT @Command
 
EXEC xp_cmdshell   @Command

Open in new window

0
 
LVL 4

Accepted Solution

by:
Daniel Jones earned 500 total points
ID: 41859760
You can set up an SQL server agent job of type cmdexec to execute the bcp utility.
First try the bcp command by itself and remember to specify the -c argument for char instead of the default bin.


Wrap this command into a scheduled job
EXEC  master..xp_cmdshell 'SQLCMD -S server\SQLSERVERDEV2005 -E -Q "SELECT TOP 10 * FROM pubs.dbo.authors" -b -o c:\myoutput.txt', no_output
0
 

Author Comment

by:ITsolutionWizard
ID: 41859761
oh sorry. I just find out our sql does not have sql job agent feature.
what is our option?
0
 
LVL 24

Expert Comment

by:Pawan Kumar
ID: 41859773
You can enable it, Right click on the SQL Server Agent and start the service.
0
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 

Author Comment

by:ITsolutionWizard
ID: 41859776
It does not have it. This is azure and I do not know why we do not have it
0
 
LVL 24

Expert Comment

by:Pawan Kumar
ID: 41859779
try this MSDN link... It has steps you need...

https://blogs.msdn.microsoft.com/ms-tech_learning_with_prasant/2014/07/09/scheduling-job-on-sql-azure/

or you may need to create a windows service..

Hope it helps !!
0
 
LVL 46

Expert Comment

by:Vitor Montalvão
ID: 41859923
It does not have it. This is azure and I do not know why we do not have it
Can't you do it in the opposite direction? In the target server (where you want the .csv file to be stored) schedule a task to export the data from Azure.
0
 
LVL 24

Expert Comment

by:Pawan Kumar
ID: 41871741
Hi ITsolutionWizard,
Appreciate feedback on this?
0
 
LVL 24

Expert Comment

by:Pawan Kumar
ID: 41884414
Hi,

Is this done ?
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now