Click here to Skip to main content
15,885,914 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Good day

I want to execute a short procedure from a another database.

The short procedure that I want to execute is in the CallAgain database. The short procedures name is: TSH_TerminalConfigUpdate.

I have written the following code, but I get an error message.

CREATE PROCEDURE SELTermConfigUpdate
AS
BEGIN
SET NOCOUNT ON;
USE [CallAgain]
Exec dbo.TSH_TerminalConfigUpdate

END
GO


-Msg 154, Level 15, State 1, Procedure SELTermConfigUpdate, Line 14
a USE database statement is not allowed in a procedure, function or trigger.

How do I execute a stored Procedure from another database?
Posted

Try with this
SQL
CREATE PROCEDURE SELTermConfigUpdate
AS
BEGIN
SET NOCOUNT ON;
USE [CallAgain]
Exec [DATABASE NAME]..TSH_TerminalConfigUpdate

END
GO

* [DATABASE NAME] = database name will be where the sp TSH_TerminalConfigUpdate is written.
 
Share this answer
 
ALTER PROCEDURE [dbo].[SELTermConfigUpdate]
AS
BEGIN
SET NOCOUNT ON;
Exec CallAgain.dbo.TSH_TerminalConfigUpdate 


--CallAgain is the other database name

-- TSH_TerminalConfigUpdate is the short procedures name
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900