Sowmya Sirsi

Sowmya Sirsi

  • NA
  • 173
  • 41.2k

BCP: Unknown option H

Jun 25 2021 7:51 AM

Hi Team,

Wriiten the below CMD to  generate a .csv file into the folder c:\Exportsqldata

DECLARE @path VARCHAR(1000) 
DECLARE @DBName varchar(255)
DECLARE @ServerName varchar(255)
SET @ServerName =@@ServerName
SET @DBName ='EmployeeService2021'
SET @path='C:\Exportsqldata' -- File location where you want to generate csv file
EXEC sp_configure 'xp_cmdshell', 1
      declare @cmd varchar(500)     
      Select @cmd = 'bcp '+
'"Select ''Name'',''Age'' from EmployeeService2021.dbo.Employee"'
    + ' QUERYOUT C:\Exportsqldata\' +'Detail.csv' +' '+ '/c /t"|" /T' +@ServerName--' -T -c"|" /T'+@ServerName
PRINt @cmd
EXEC master..xp_cmdshell @cmd;

Once I execute it getting error as "BCP: Unknown option H"

Please do the needful


Answers (3)