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 2005 Forums
 Transact-SQL (2005)
 One stored proc calling another

Author  Topic 

lols
Posting Yak Master

174 Posts

Posted - 2007-12-07 : 01:32:23
Hi,

I have a stored proc called MyProc1

CREATE PROCEDURE [dbo].[MyProc1] 
@var1 char(2),
@var2 smallint,
@var3 datetime,
@var4 OUTPUT
AS
BEGIN
DECLARE @STR int
' Code comes here to calculate var4 and STR
RETURN @STR
END


Problem :

I want to call MyProc1 within another proc called 'CallTheProc' and receive the value @STR

I have written so far :

declare @Id char
EXEC MyProc1 'AV',23, getdate(), @Id OUTPUT
print @Id


However I get an error 'Incorrect syntax near ')'. I do not get any values. I know I am using @Id as char whereas it needs to be int. But I want to receive the value as a char.

How can I do so?

Thanks.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2007-12-07 : 01:44:23
why dont you make it a User Defined Function?
Go to Top of Page

lols
Posting Yak Master

174 Posts

Posted - 2007-12-07 : 02:05:11
Coz the one i am calling is on the Client end. So cannot be changed :) I need a solution of one stored proc calling the other as explained above.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-12-07 : 02:09:47
Try calling

declare @Id varchar(10), @date datetime
set @date=getdate()
EXEC MyProc1 'AV',23, @date, @Id OUTPUT
print @Id

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

lols
Posting Yak Master

174 Posts

Posted - 2007-12-07 : 02:41:21
hi,
thanks..but the prob is when i execute your query, I am getting the value of @var4. Whereas I need the value of @STR.

thanks.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-12-07 : 03:21:23
And since @str is returned as a resultset (yes! with one column and one row) insert it into a table variable.

declare @s table (i int), @Id varchar(10), @date datetime
set @date=getdate()

insert @s
EXEC MyProc1 'AV',23, @date, @Id OUTPUT
print @Id
select * from @s



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page
   

- Advertisement -