SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
Register Now and get your question answered!
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 execute a stored proc within a string through xp_c
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

12 Posts

Posted - 05/16/2013 :  12:12:06  Show Profile  Reply with Quote

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 !!!


Constraint Violating Yak Guru

352 Posts

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

Go to Top of Page

Bustaz Kool
Flowing Fount of Yak Knowledge

1827 Posts

Posted - 05/16/2013 :  12:18:52  Show Profile  Reply with Quote
"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

Starting Member

12 Posts

Posted - 05/16/2013 :  15:21:09  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000