Procedure expects parameter 'command_string' of type 'varchar'

  • hello all.

    I used this procedure for export to xml file:

    alter PROC makeXML

    AS

    DECLARE @myXml xml,@SQL nvarchar(max)

    SET @myXml = (SELECT * FROM QMS_QmsBase FOR XML AUTO)

    SET @SQL= 'bcp "exec @myXml" QUERY OUT f:\azizi\filename.xml -w -r -t -SNik-Azizi -T'

    EXEC Master..xp_CmdShell @SQL

    but get this error:

    Procedure expects parameter 'command_string' of type 'varchar'

    how to solve this error?thanks

  • change @SQL to varchar(max) instead of nvarchar(max)

    Also dont use *, you should use the columns names.

    Also on that remeber that * is a CMD wildcard like % is in SQL so even more reason to use column names just incase it throws a wobbler at you.

  • thank you for your reply,

    i use your note but get the same error:crying:

  • Missed one thing, the MyXML variable will need to be varchar too

    SO you might as well just do the following

    DECLARE @SQL varchar(max)

    SET @SQL= 'bcp "SELECT column_names FROM QMS_QmsBase FOR XML AUTO" QUERY OUT f:\azizi\filename.xml -w -r -t -SNik-Azizi -T'

    EXEC Master..xp_CmdShell @SQL

  • i use this:

    alter PROC makeXML

    AS

    DECLARE @myXml xml,@SQL varchar(max)

    SET @myXml = (SELECT QMS_QmsBaseName FROM QMS_QmsBase FOR XML AUTO)

    --SET @SQL= 'bcp "exec @myXml" QUERY OUT f:\azizi\filename.xml -w -r -t -SNik-Azizi -T'

    EXEC Master..xp_CmdShell 'bcp "exec @myXml" QUERY OUT f:\azizi\filename.xml -w -r -t -SNik-Azizi -T'

    --exec makeXML

    and solve previouse error but sp doesnot work and result of its:

    Copy direction must be either 'in', 'out' or 'format'.

    usage: bcp {dbtable | query} {in | out | queryout | format} datafile

    [-m maxerrors] [-f formatfile] [-e errfile]

    [-F firstrow] [-L lastrow] [-b batchsize]

    [-n native type] [-c character type] [-w wide character type]

    [-N keep non-text native] [-V file format version] [-q quoted identifier]

    [-C code page specifier] [-t field terminator] [-r row terminator]

    [-i inputfile] [-o outfile] [-a packetsize]

    [-S server name] [-U username] [-P password]

    [-T trusted connection] [-v version] [-R regional enable]

    [-k keep null values] [-E keep identity values]

    [-h "load hints"] [-x generate xml format file]

    [-d database name]

    NULL

    now.how do i do?

  • Well if MyXML is already the output you want to pump out to a file, you dont need to exec it, you need to select it as there will be nothing to execute.

    Query Out is one word not two, QUERYOUT

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply