BCP Parameter Passing possible ?

  • I have this query where I'm trying to get data into Test.csv from table TableName where ColA has value of sqlnaive.

    bcp "select * from DatabaseName.dbo.TableName where ColA ='sqlnaive'" queryout "C:\DataMigration\Test.csv" -SServerName -T -c

    Now I want to run it with a parameter where whatever value is passed it should work. Is it possible ?

  • How are you executing that command? From a batch file? If that's the case, you can refer to the values of parameters passed to the batch file as %1 (first parameter), %2 (second parameter) etc.

    --------------------------------------------------------------------------
    A little knowledge is a dangerous thing (Alexander Pope)
    In order for us to help you as efficiently as possible, please read this before posting (courtesy of Jeff Moden)[/url]

  • It worked perfectly. Thanks a lot. 🙂

  • Glad it did 😉

    --------------------------------------------------------------------------
    A little knowledge is a dangerous thing (Alexander Pope)
    In order for us to help you as efficiently as possible, please read this before posting (courtesy of Jeff Moden)[/url]

  • Hi, I want to do the same thing from within a procedure.

    Trying to do something like the following:

    Declare @var_XML xml

    :

    :

    :

    :

    Select @var_XML = (Select * From Tab_Name For XML PATH ('privilege'))

    -- Select Select @var_XML -- This works fine.

    -- But the following will not work (says @var_XML must be declared.

    EXEC xp_cmdshell 'bcp "Select Select @var_XML " queryout "C:\tab_name.xml" -S MyServer -U sa -P pwd -c'

    Is there a way to get this to work?

    Many thanks

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

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