I have the bcp command below from a stored procedure. The stored procedure is constructed as follows:
SET @sqlCmd = 'bcp "' + @sqlStr + '" queryout "' + @offersFilename + '" -w -T';
EXEC xp_cmdshell @sqlCmd;
When I try to run this, I get the bcp usage response, meaning there is some syntax error in my @sqlCmd.
Using PRINT @sqlCMD, I get the following printout. Could someone please advise where I am getting it wrong. Thanks.
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