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
 General SQL Server Forums
 New to SQL Server Programming
 change to sp

Author  Topic 

CrazyT
Yak Posting Veteran

73 Posts

Posted - 2010-07-26 : 12:24:25
"use " + Database + " exec storedprocedurename

how do i convert this into a stored procedure

X002548
Not Just a Number

15586 Posts

Posted - 2010-07-26 : 12:56:59
EXEC db.owner.sproc

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2010-07-26 : 12:57:45
Do you actually need USE, or will the equivalent of this do:

"EXEC " + Database + ".dbo.storedprocedurename"

?

Go to Top of Page

CrazyT
Yak Posting Veteran

73 Posts

Posted - 2010-07-26 : 13:02:06
i need the use
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2010-07-26 : 13:24:54
it's not going to work...you would also need a GO

You can easily test it

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

slimt_slimt
Aged Yak Warrior

746 Posts

Posted - 2010-07-26 : 13:24:59
as brett said:

EXEC NameOfDatabase.DatabaseOwner.SP_MyProcedure

for example:

EXEC AdventureWorks2008.dbo.SP_GetLastOrderDate

and you can run this code from any of the database on the instance and it will execute
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2010-07-26 : 13:29:24
And if it's on a different server, you can create a linled server and use the 4 part name

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page
   

- Advertisement -