Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to export data from SQL Server Management Studio to Text File

Status
Not open for further replies.

2Plan

MIS
Mar 29, 2005
55
US
I will only have access (possibly only read-only access and ability to export) to the SQL Server 2005 Management Studio or the SQLCMD utility to export the data to a "fixed width" text file.

Is there a script or Transact-SQL code that I can run in the SQL Server 2005 Management Studio or the SQLCMD utility to export the data below to a "fixed width" text file?

Thanks in advance for any assistance.

Rout Block_ _Date_ D Bus_ D Trip Time_ On_ Off

392 392001 102008 1 7036 6 0451 25.0 2 0
392 392001 102008 1 7036 0 0516 28.0 7 8
392 392001 102008 1 7036 1 0600 42.0 19 19
392 392001 102008 1 7036 0 0700 48.0 15 18
392 392001 102008 1 7036 1 0800 46.0 17 15
392 392001 102008 1 7036 0 0900 50.0 6 8
392 392001 102008 1 7036 1 1000 48.0 9 10
392 392001 102008 1 7036 0 1100 50.0 20 27
392 392001 102008 1 7036 1 1200 48.0 16 10
392 392001 102008 1 7036 0 1300 50.0 16 18
392 392001 102008 1 7036 1 1400 50.0 31 27
392 392001 102008 1 7036 0 1500 51.0 22 22
392 392001 102008 1 7036 1 1600 48.0 23 23
 
In my opinion, the best way to export data to fixed width text files is to use the BCP utility with a format file. It's kind-of-a pain to set it up, but will give you the best performance.

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
If I use the BCP utility, what would the script look like to set up the first two or three columns of the "fixed width" text file? Also need to export column headers. I'm currently reading more info on the BCP utility, but any additional help would be appreciated.

Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top