Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I m trying to write query result to txt file. Here is my code:

exec master..xp_cmdshell 'bcp "select * from Leasings" queryout "DHCPLog.txt" -c -t,-T MyServerIP' 

But the result is :

enter image description here

And there is no row in DHCPLog.txt. Do you have any suggestion about this?



share|improve this question

I think that you are missing a space after the comma and that you need to use the -S flag to specify the server name because -T is not enough. A command similar to the following works for me here:

exec master..xp_cmdshell 'bcp "select * from Leasings" queryout "DHCPLog.txt" -c -t, -T -S MyServerIP'
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.