Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Fixed Length test file

Author  Topic 

rjackman1959
Yak Posting Veteran

60 Posts

Posted - 2009-01-30 : 15:33:30
I there a way to save or concatenate the output of a select statement to a fixed length test file on the local PC? Here is the output. Thank You in advance

20090107 4915A 3758UPTC 7498 00000131 720576 20081231 00000344 000000010166
20090112 4930A 3758UPTC 7502 00000131 720587 20081231 00000344 000000010172

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2009-01-30 : 15:41:37
one way is to go to:

Tools | Options | Query Results | Sql Server | Results to Text

Change the options accordingly then change the query properties to "output to file". When you execute the statement you will get a Save File dialogue where you can browse to your local directory.

Be One with the Optimizer
TG
Go to Top of Page

rjackman1959
Yak Posting Veteran

60 Posts

Posted - 2009-01-30 : 16:06:12
Is there a way to do this on only select queries? I am call this procedure from an Excel speadsheet.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-01-30 : 16:21:02
You can do this via bcp.

From the command line: bcp "your query" queryout C:\SomeFile.csv -Ssomeserver\someinstance -T -t, -c -r\r\n

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

rjackman1959
Yak Posting Veteran

60 Posts

Posted - 2009-01-30 : 16:55:41
Sorry Tara

What command line? I am not familiar with bcp. Also I understand what the SomeFile.csv and Ssomeserver, but I don't know what the someinstance is. Please excuse my inexperience
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-01-30 : 19:02:36
Command line: Start..Run..cmd, hit enter.

For bcp documentation, you can type bcp /? from the cmd window or visit SQL Server Books Online.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-01-31 : 08:07:33
quote:
Originally posted by rjackman1959

Sorry Tara

What command line? I am not familiar with bcp. Also I understand what the SomeFile.csv and Ssomeserver, but I don't know what the someinstance is. Please excuse my inexperience


or just use sql export import wizard with text file as destination and your query as source to get data into file.
Go to Top of Page
   

- Advertisement -