Solved

SQL Server Query automated and output to csv

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

The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

Question has a verified solution.

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

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

729 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