Hi, How can we append an existing flat file with a query result [it may be more than one records.] i tried this way, however, it will delete the content of the flat file [.txt] rather than append xp_cmdshell "bcp mydb..vwTest out D: est.txt -Usa -Ppassword" Thanks
See if this helps: http://social.msdn.microsoft.com/Fo...e/thread/9e5cf4d4-42e5-4444-9f64-2d2d0ebfd28f
Hi frank, i saw the comments "BCP always overwrites any file that might already be there. There is no option to append [] " could you please suggest any solution? [dont want ssis]. Thanks
Never tried that myself, but what about a batch file in which you bcp out to a dummy file and then append that dummy file to the final one. Should be as simple as echo. >> <finalfile>.csv
[quote user="FrankKalis"] Never tried that myself, but what about a batch file in which you bcp out to a dummy file and then append that dummy file to the final one. Should be as simple as echo. >> <finalfile>.csv [/quote] That is the way to go. When I posted the script on how to export data to excel, so many users were asking me how to export data along with column headers. The only possible method I could think of is to use dummy file and append to main file FYI, refer point 5 http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=49926 This should also apply to text files