Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

SQL Server Query automated and output to csv

Posted on 2013-12-06
4
Medium Priority
?
419 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
[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
  • 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 2000 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

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 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.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

730 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