Solved

SQL Server Query automated and output to csv

Posted on 2013-12-06
4
396 Views
Last Modified: 2013-12-14
In SQL Server 2008 I need to do the following and am new to SQL Server. I've been searching the web to see the best solution.

1) query table
2) output results to .csv file with two header lines, not just one
3) perform weekly
4) make automated

Thank you for your help.
0
Comment
Question by:newtoperlpgm
  • 2
  • 2
4 Comments
 
LVL 12

Expert Comment

by:Tony303
ID: 39702581
Hi,

Let me work backwards to help get you started.

I am assuming you have a SQL 2008 machine available to you and it has the SQL Agent configured and running. The SQL Agent will be the tool to achieve item 3 and 4 in your question.

SQL Agent can be found generally your SSMS (SQL Server Management Studio). This is the GUI frontend to administer the SQL Environment.

The next thing to do is use the SQL Agent to create a new SQL Job.
This job will be used to accomplish item 1 and 2 in your question.

Here is a great solution already on EE that gives you an example of the code needed in the SQL Agent job...

http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/Q_27913009.html

See how you go...

T
0
 

Author Comment

by:newtoperlpgm
ID: 39707158
Yes I have all the tools I need to connect to the database.  The solution to which you referred uploads the csv file into a table, but I need to do the opposite, I need to download the data from the database into a csv file.  
Thanks.
0
 

Author Comment

by:newtoperlpgm
ID: 39707163
I may have misunderstood, I think you were only referring to the bulk copy (below) step from the solution you referenced.
job step
xp_cmdshell 'bcp a.dbo.lang out c:\mssql\mailcsv.csv -n -T'

Thank you.
0
 
LVL 12

Accepted Solution

by:
Tony303 earned 500 total points
ID: 39707195
Yeah the out part is the export under bcp.

xp_cmdshell 'bcp a.dbo.lang out c:\mssql\mailcsv.csv -n -T'
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Audit has been really one of the more interesting, most useful, yet difficult to maintain topics in the history of SQL Server. In earlier versions of SQL people had very few options for auditing in SQL Server. It typically meant using SQL Trace …
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

747 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

12 Experts available now in Live!

Get 1:1 Help Now