Solved

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

Posted on 2014-11-19
4
428 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
4 Comments
 
LVL 3

Accepted Solution

by:
Richard Obenchain earned 250 total points
Comment Utility
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
Comment Utility
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 45

Assisted Solution

by:Vitor Montalvão
Vitor Montalvão earned 250 total points
Comment Utility
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
Comment Utility
I really appreciate Vito Montalvao he really taught me a few things doing this effort.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

SQL Server  2012 Release with lots of Enhancements in Database Engine functions, SSIS, SSRS and some of new services like Data Quality Server and Master Data Service. Of particular interest, and the focus of this Article is SSIS. So, time to elab…
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

762 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now