Solved

SQL Server Query automated and output to csv

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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Trying to get a Linked Server to Oracle DB working 21 76
SQL Stored Proc - Performance Enhancement 15 77
Sql query with where clause 2 45
How can I use this function? 3 32
This is basically a blog post I wrote recently. I've found that SARGability is poorly understood, and since many people don't read blogs, I figured I'd post it here as an article. SARGable is an adjective in SQL that means that an item can be fou…
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

740 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