This should work, note the pair of single-quotes around the stored procedure parameter:
EXEC xp_cmdshell 'bcp "EXEC DatabaseName.dbo.pn_FlatProductXML ''KA-0009'' " queryout "C:\test.txt" -T -c '
Question
I am trying to get an XML file out from my stored procedure using xp_cmdshell and bcp. The example of a BCP statement work... I get a file... So, knowing that works, and the stored procedure works, I cannot get them to work together.
-- This works:
EXEC xp_cmdshell 'bcp "SELECT * FROM sysfiles" queryout "C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\Backup\table.xml" -T -c -t,'
-- This works:
EXEC pn_FlatProductXML "KA-0009"
I'm getting tripped up in the single and double quotes, etc... Can anybody help?
Solution
This should work, note the pair of single-quotes around the stored procedure parameter:
EXEC xp_cmdshell 'bcp "EXEC DatabaseName.dbo.pn_FlatProductXML ''KA-0009'' " queryout "C:\test.txt" -T -c '