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 2000 Forums
 SQL Server Development (2000)
 Dynamic Header to a text file

Author  Topic 

sqllearner
Aged Yak Warrior

639 Posts

Posted - 2007-05-11 : 18:00:56
I have already created the output file using the exec master..xp_cmdshell and all the fields are working based on the format.Now the problem which I have is all the files I generate should have a header with the file name(8 in length)and while using bcp I was not able to create the header.Is there any way to append this value to the first line of the output text file that's getting created.

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-05-11 : 18:10:58
see if this helps you:
http://weblogs.sqlteam.com/mladenp/archive/2006/07/25/10771.aspx

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
Go to Top of Page

sqllearner
Aged Yak Warrior

639 Posts

Posted - 2007-05-11 : 18:25:15
This is using the column header for the data retreived but in my case Iam not retrieving the column names.I just want to create a header fo each file which I create using the BCP.The header is just the file name and rest all the values from row 2 will be the data retreived through BCP
Go to Top of Page

sqllearner
Aged Yak Warrior

639 Posts

Posted - 2007-05-11 : 19:31:42
I used
DECLARE @cmd sysname, @var sysname
SET @var = 'testworld'
SET @cmd = 'echo ' + @var + '>> \\fildev01\Archive\Target\test.txt'
EXEC master..xp_cmdshell @cmd
But this is getting appended to the last row but I want this to be the first line as a header
Go to Top of Page

sqllearner
Aged Yak Warrior

639 Posts

Posted - 2007-05-12 : 18:11:28
I tried creating another file with a header and merged this 2 file like

copy newtest1.txt + test.txt newtest1.txt but the problem here is the end of file character is available when I merge it from test.txt and that will be a problem.If I can remove that character then it can be a work around.Please somebody help
Go to Top of Page
   

- Advertisement -