I got a much nicer way to do this.
1. Setup the following table:
CREATE TABLE TXTTOFILE (
LINE varchar (2000) NULL ,
IDCOL int IDENTITY (1, 1) NOT NULL
)
2. Then put a clustered index on IDCOL.
3. Now insert each line that you want to go into the file into this table without the carriage returns
INSERT INTO TXTTOFILE SELECT @string1_to_write
INSERT INTO TXTTOFILE SELECT @string2_to_write
. . .
. . .
4. Now with a single cmdshell you can output the results
exec xp_cmdshell 'BCP TXTTOFILE OUT D:\TXTFILE.TXT /Uuser /Ppassword /c'
Now if you did it right, you should have a nice file with carriage returns and all! The key to this is the clustered index on IDCOL which keeps the file in the order which it was inserted. The BCP will just do the equilivant to a SELECT * FROM on the table, which will be in the order you inserted it.
If you are still having problems doing it this way, post your code and I can go through it.