?
Solved

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

Posted on 2014-11-19
4
Medium Priority
?
523 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 1000 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 51

Assisted Solution

by:Vitor Montalvão
Vitor Montalvão earned 1000 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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
I have a large data set and a SSIS package. How can I load this file in multi threading?
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

771 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