Solved

MS SQL export CSV & schedule It

Posted on 2016-10-25
9
104 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 29

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
 
LVL 1

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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 29

Expert Comment

by:Pawan Kumar
ID: 41859773
You can enable it, Right click on the SQL Server Agent and start the service.
0
 
LVL 1

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 29

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 51

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 29

Expert Comment

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

Expert Comment

by:Pawan Kumar
ID: 41884414
Hi,

Is this done ?
0

Featured Post

Ready to get started with anonymous questions?

It's easy! Check out this step-by-step guide for asking an anonymous question on Experts Exchange.

Question has a verified solution.

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

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
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.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

626 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