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
 export sql file

Author  Topic 

DWMelton
Starting Member

5 Posts

Posted - 2012-07-13 : 09:21:34
I have a query that results in output - now the customer wants me to have the export of the query to be in a flat file format with no hearders but each column in a certian place - ie..
company is 1-4 desc 5-25 date 26-33 ect

any suggestions on how to approach

xhostx
Constraint Violating Yak Guru

277 Posts

Posted - 2012-07-13 : 09:29:27
well you didnt really gave enough details of the output format:

anyways try this:

exec master..xp_cmdshell 'bcp yourdb..yourtable out yourfile.txt /c /Username /Password /r\n'

--------------------------
Get rich or die trying
--------------------------
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-07-13 : 09:56:10
better to use query out option in bcp if you want columns to be of fixed width. make sure you cast them to appropriate size before you do bcp

Another method is to use ssis with fixed length file connection

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -