Solved

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

Posted on 2014-11-19
4
462 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
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 47

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

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…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

773 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