Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 execute a stored proc within a string through xp_c

Author  Topic 

imransi17
Starting Member

12 Posts

Posted - 2013-05-16 : 12:12:06
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,

djj55
Constraint Violating Yak Guru

352 Posts

Posted - 2013-05-16 : 12:15:19
1) do you really need xp_cmdshell?
2) have you tried execute sp_executesql @cmd? (without 'exec' at the begining)

djj
Go to Top of Page

Bustaz Kool
Master Smack Fu Yak Hacker

1834 Posts

Posted - 2013-05-16 : 12:18:52
"exec" is a SQL statement. xp_cmdshell lets you execute things at the OS level. The OS doesn't know what "exec" means. What are you trying to actually accomplish?

=================================================
I am not one of those who in expressing opinions confine themselves to facts. (Mark Twain)
Go to Top of Page

imransi17
Starting Member

12 Posts

Posted - 2013-05-16 : 15:21:09
djj55, i didn't needed xp_cmdshell. you are right. it worked as

exec stored_proc_name @DB_Name, @user_id, @password, @Path1

Thank you :)


Brustaz Kool: Thank you soo much. you are right. I shouldn't be using xp_cmdshell in this format.

Thanks :)
Go to Top of Page
   

- Advertisement -