Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

call a procedure

Status
Not open for further replies.

immad

Programmer
May 31, 2013
7
0
0
i have a procedure name query


i want to make a procedure name proc and call this query procedure inside this procedure
 
Bad naming :)
Code:
CREATE PROCEDURE MyProc
AS
BEGIN
   CALL [Query]
END
If [QUERY] is placed in another Database you should use full anme of the proc:
DBName.schema.ProcedureName

Borislav Borissov
VFP9 SP2, SQL Server
 
I don't know if CALL is a SQL Server function, or not. But this should work;
Code:
create procedure test2
as
select getdate()
go

create procedure test1
as
exec test2
go

test1
 
My mistake, it is EXEC not CALL :)
Code:
CREATE PROCEDURE MyProc
AS
BEGIN
   [COLOR=red]EXEC[/color] [Query]
END

Borislav Borissov
VFP9 SP2, SQL Server
 
and if you want to execute an SP within another SP and use the returned results in a join, you can use a temp table..

Code:
BEGIN
	CREATE TABLE #TEMP (   
		ID int,
		Name varchar(30),
		Tel varchar(12)
    )

	INSERT INTO #TEMP (ID, Name, Tel)   
	EXEC dbo.spGetPeople


	SELECT Name, Tel, Address, PostCode
         FROM Addresses a 
         JOIN #TEMP t ON a.ID = t.ID

	DROP TABLE #TEMP
END

"In complete darkness we are all the same, it is only our knowledge and wisdom that separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Free Dance Music Downloads
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top