[英]Using BCP and xp_cmdshell with T-SQL inside SSMS. “The syntax of the command is incorrect”
因此,我與BCP一起玩耍以更好地了解它,並遇到了一個我無法弄清的問題。 我收到一個錯誤,“命令的語法不正確”。
我已經測試了正確構建的完整文件路徑以及本身正確完成的select查詢。 有什么想法嗎?
我使用的代碼是:
DECLARE @fileName varchar(128)
DECLARE @filePath varchar(128)
DECLARE @completeFilePath varchar(128)
DECLARE @sqlCmd varchar(4000)
DECLARE @BCPSwitches VARCHAR(64)
SET @filePath = 'xxxxxx'
SELECT TOP 5 [EMP]
,[SSNO]
,[NAME]
,[STREET]
INTO #ParticipantIdentifiers
FROM xxxxxxxxx
SET @BCPSwitches = '-w -T -t |'
SET @fileName = 'xxxxx.txt'
SET @completeFilePath = @filePath + @fileName
SET @sqlCmd = 'bcp "SELECT * FROM #ParticipantIdentifiers" queryout "'+ @completeFilePath + '" ' + @BCPSwitches
EXEC DemoDB..xp_cmdshell @sqlCmd
我認為終止符“ |” -t之后(在@BCPSwitches中)也需要用引號引起來,因為shell可能會將其解釋為輸出管道。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.