Solved

How to export a csv comma delimited sorted file using SQL Server?

Posted on 2014-11-19
4
504 Views
Last Modified: 2016-02-13
I am really struggling trying to automate a script to export a sql server table into a cvs file that can sorted and put in a shared folder.  I have try the export tool in sql server but can't find a way to sort the file.  I also try to BCP the file in to a cvs file and couldn't get that to work.  I know that this can be done.  Please advised.
0
Comment
Question by:kdbworld
[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
4 Comments
 
LVL 3

Accepted Solution

by:
Richard Obenchain earned 250 total points
ID: 40454210
If it's just a matter of sorting, use a query source instead of a table and sort in the query, selecting all fields.

Then save the SSIS package for executing later, and modify it or schedule it as needed.
0
 
LVL 8

Expert Comment

by:vr6r
ID: 40454212
I would probably do this with a powershell script.  I don't have a sample with me right now but we do this all the time at work to automate exports from sql to csv and/or email.  Once you're done with the script you can execute it from a simple .bat file and schedule the .bat to run whenever you want from the normal windows task scheduler.

Found this with a quick search, may help get you started if you want to give it a shot:
http://beyondrelational.com/modules/2/blogs/908/posts/18005/exporting-from-sql-server-to-csv-file-using-powershell.aspx
0
 
LVL 50

Assisted Solution

by:Vitor Montalvão
Vitor Montalvão earned 250 total points
ID: 40454840
I'm with Richard. In the Export wizard you can provide a query instead of a table, then you just need to provide the query with the ORDER BY clause. Example:
SELECT *
FROM MyTableName
ORDER BY ColumnName

Open in new window

0
 

Author Closing Comment

by:kdbworld
ID: 40481449
I really appreciate Vito Montalvao he really taught me a few things doing this effort.
0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

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…
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.
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
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 …

717 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