The below command is sent to me via Outlook email message.
I connected to my local server using my windows user account as system administrator.
Declare @str nvarchar(4000)
Set @str =N'BCP KodyazDB.dbo.Brands out c:\export.txt -S PCKodyaz\yukon –U mysqllogin –P myloginpwd'
Exec master..xp_cmdshell @str
Copied and ran. The returned error message is as follows:
Unknown argument 'ûU' on command line. or Unknown argument 'ûP' on command line.
Although it seen as -, when I copied the code on a frontpage document I realized that it was converted to – .The Microsoft SQL Server Management Studio is aware of the difference between the characters of - and – but displays them as same.
I manually deleted the dashes and rewrite them again.
Declare @str nvarchar(4000)
Set @str =N'BCP KodyazDB.dbo.brands out c:\export.txt -U mysqllogin -P myloginpwd -S PCKodyaz\yukon'
Exec master..xp_cmdshell @str
Returned the following output message:
Enter the file storage type of field BrandId [smallint]:
I added a new argument to the BCP command -c
Declare @str nvarchar(4000)
Set @str =N'BCP KodyazDB.dbo.brands out c:\export.txt -c -U mysqllogin -P myloginpwd -S PCKodyaz\yukon'
Exec master..xp_cmdshell @str
output message is displayed as :
NULL
Starting copy...
NULL
361 rows copied.
Network packet size (bytes): 4096
Clock Time (ms.): total 1
NULL
This is the happy ending.