Results 1 to 3 of 3
  1. #1
    Join Date
    May 2013
    Posts
    7

    Red face Unanswered: execute a stored proc within a string through xp_cmdshell

    Hello,

    I am trying to execute a stored proc like this


    Declare @cmd varchar(1000)
    Declare @Path1 varchar (1000)
    Declare @user_id varchar (50)
    Declare @password varchar (50)

    set @cmd = 'exec' + ' ' + stored_proc_name' + ', ' + @user_id +', ' + @password + ', ' + @Path1
    exec master..xp_cmdshell @cmd


    ERROR I am getting = 'exec' is not recognized as an internal or external command,

    Please help !!!!

    Thanks,

  2. #2
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    The xp_cmdshell procedure submits the argument to the Windows command processor. You apparently want to submit to the SQL command processor. If I guessed correctly about what you want, then I would use:
    Code:
    Declare @Path1      varchar (260) = 'Some value'
    Declare @user_id    varchar (50)  = 'Some value'
    Declare @password   varchar (50)  = 'Some value'
    
    EXECUTE ('exec stored_proc_name ', @user_id, ', ', @password, ', ',@Path1)
    -PatP
    In theory, theory and practice are identical. In practice, theory and practice are unrelated.

  3. #3
    Join Date
    Aug 2004
    Location
    Dallas, Texas
    Posts
    831
    Or use sp_executesql...

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •