cannot get xp_seller and bcp to play nice with stored procedure with parameter

StackOverflow https://stackoverflow.com/questions/17286451

  •  01-06-2022
  •  | 
  •  

سؤال

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?

هل كانت مفيدة؟

المحلول

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 '
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top