Solved

SQL Server Query automated and output to csv

Posted on 2013-12-06
4
401 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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

825 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