It is correctly suggested. You should have seek more help from local/online BOL. Try this EXEC xp_cmdshell 'bcp "select top 5 * from sw_tokenDeletion" queryout "c:\TestMailfilename.txt" -c -U sa -P temp123 -S 172.25.11.20' Two things to be noted 1. You need to specify `queryout` keyword when you are copying data from a query 2. There should not be brackets around the Server IP/NAME Hope it helps.