xp_xmdshell and BCP select string problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • radcaesar
    Recognized Expert Contributor
    • Sep 2006
    • 759

    xp_xmdshell and BCP select string problem

    exec master..xp_cmds hell 'bcp "SELECT '<?xml version="1.0" encoding="utf-8"?>' UNION ALL SELECT (SELECT * FROM tablename FOR XML EXPLICIT)" queryout c:\test.xml -w -r "" -Sdataserver -Usa -Ppassword'

    The above query shows syntax error at '<'. I was missed something here in string manipulation. Can any one have idea, where i miss?
  • ck9663
    Recognized Expert Specialist
    • Jun 2007
    • 2878

    #2
    Run your query (not the BCP) first in query analyzer.

    I have not tried this myself. But in a UNION, I think you should have a name for the column of your primary query where the subsequent query will be union-nized (if there's such a word).

    -- CK

    Comment

    • radcaesar
      Recognized Expert Contributor
      • Sep 2006
      • 759

      #3
      I Had run the whole xp_cmdshell with BCP in SSMS and its working fine. I want to add the xml root tag at the top of the xml ducment. So that i add the below line and it fails.

      SELECT '<?xml version="1.0" encoding="utf-8"?>' UNION ALL

      Any suggestions ?

      Comment

      Working...