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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 issue with txt file

Author  Topic 

ramemail.n
Starting Member

8 Posts

Posted - 2010-07-28 : 12:27:48
declare @dateformat varchar(100)
select @dateformat = convert(varchar(15), getdate(),102)
select @dateformat
declare @sql varchar(100)
set @sql = 'bcp "SELECT top 10 * FROM report..carriers" queryout "D:\bcptest' + @dateformat + '.txt" -T -c -t,'
select @sql
exec xp_cmdshell @sql

using above script i am able to copy the data from table to text file
but i am not getting header how to get the header in each file.

Thanks,
Rammohan

Rammohan N

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-07-28 : 13:00:47
Moved topic out of Script Library since your topic is not appropriate for that forum.

Bcp does not give you the header information. You can get the header via a UNION view with CONVERT, however it's better to just use SSIS.

Here's the bcp header solution though: http://www.dbforums.com/microsoft-sql-server/989335-bcp-out-headers.html

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

Subscribe to my blog
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-07-29 : 04:44:10
Also refer point 5
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=49926

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -