Solved

MS SQL export CSV & schedule It

Posted on 2016-10-25
9
41 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 17

Expert Comment

by:Pawan Kumar Khowal
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 3

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 17

Expert Comment

by:Pawan Kumar Khowal
ID: 41859773
You can enable it, Right click on the SQL Server Agent and start the service.
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

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 17

Expert Comment

by:Pawan Kumar Khowal
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 45

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 17

Expert Comment

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

Expert Comment

by:Pawan Kumar Khowal
ID: 41884414
Hi,

Is this done ?
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
separate column 24 19
Sort by Month and Year - SQL 3 22
Copy Database Wizard Error 3 20
SQL Date Retrival 7 26
Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Viewers will learn how the fundamental information of how to create a table.

708 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

19 Experts available now in Live!

Get 1:1 Help Now