May 16, 2013 at 9:46 am
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 !!!!:unsure:
Thanks,
May 16, 2013 at 9:52 am
Why are you trying to execute a stored procedure from the command line?
May 16, 2013 at 9:58 am
Hello Lynn,
Because I have to exec the same proc many times for different Paths and different Databases in multiple servers. so its easier to use and control variables in a table if they change in future.
May 16, 2013 at 10:05 am
Still doesn't answer the question. EXEC isn't a command or program that the operating system understands.
May 16, 2013 at 10:09 am
So how can I execute what I am trying to execute above from within SQL Server? Please...
May 16, 2013 at 10:13 am
I know this isn't going to answer your actual question but the one you posted is like this:
exec stored_proc_name @user_id, @password, @Path1
May 16, 2013 at 10:39 am
Leaving aside the question of whether this is a good idea or not, you can use the command line utility SQLCMD to log in to servers and run stored procedures that exist there:
http://msdn.microsoft.com/en-us/library/ms162773.aspx
So instead of building the string with 'EXEC' you'd build it with SQLCMD with the appropriate parameters.
May 16, 2013 at 1:15 pm
Lynn Thank YOU so much..... 4 eyes better than 2 ...:-)
David you are absolutely right... I will use this in another task though 🙂
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply