0
當我有從存儲過程下面的BCP命令。該存儲過程的結構如下:T-SQL bcp語法問題輸出XML
SET @sqlCmd = 'bcp "' + @sqlStr + '" queryout "' + @offersFilename + '" -w -T';
EXEC xp_cmdshell @sqlCmd;
當我嘗試運行此,我得到的BCP使用響應,這意味着在我@sqlCmd一些語法錯誤。
使用打印@sqlCMD,我得到下面的打印輸出。有人可以請告訴我哪裏錯了。謝謝。
bcp "select custID as ""@id"",
(
SELECT familyDesc as ""familyDesc"",
upc as ""upc"",
itemDesc as ""itemDescription"",
offerCode as ""offerCode"",
offerDesc as ""offerDesc"",
validFrom as ""validFrom"",
validTo as ""validTo"",
cast(round(price,2) as decimal(19,2)) as ""price"",
imageURL as ""imageURL""
FROM tblCustomerOffers t2 where t1.custID=t2.custID
for XML PATH('Offer'), TYPE
)
from tblCustomerOffers t1
group by custID
FOR XML PATH('Customer'), ROOT ('Offers'), ELEMENTS"
queryout "D:\offers\customerOffers.xml" -w -T
非常感謝@Eric波特,這種解決方法(全球溫度和PowerShell腳本)是,我可以在此期間實現至少自動化的全過程的最佳解決方案。這很奇怪,因爲在DOS提示符下輸入上面打印的整個bcp命令可以很好地工作 - 但是將其包裝在存儲過程中並且所有地獄都打破了。非常感謝! – Ceasar