Click here to Skip to main content
15,886,629 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Hi,

I'd like to use an SP output to assign it to a variable of another SP Like here, I want to output of the GetLinage SP be assigned to @linage in InsertLog SP, But an error I get is that,
SQL
Procedure or function GetLinage has too many arguments specified.


I Don't know if what I'm mistaking,


SQL
EXEC InsertLog 'MenuItem78', 'thisrout', 'thisbutton', '2000-01-01 00:00:00' , 123

ALTER PROCEDURE 
InsertLog(
	@formName nvarchar,
	@buttonRout nvarchar,
	@buttonName nvarchar,
	@clickDateTime DateTime,
	@userCode bigint
	)

AS
BEGIN

DECLARE
@linage nvarchar
EXEC GetLinage @formName, @linage  OUTPUT



INSERT INTO 
LogTable(
	FormName,
	Linage,
	ButtonRout,
	ButtonName,
	ClickDateTime,
	UserCode
	)
VALUES(
	@formName,
	@linage,
	@buttonRout,
	@buttonName,
	@clickDateTime,
	@userCode
	)

END
GO


The GetLinage SP is as follows:

SQL
CREATE PROCEDURE GetLinage (@formname nvarchar)
AS

SELECT Linage
FROM formslist
WHERE (formslist.Formname = @formname)


GO


What I have tried:

I'm working on it and other different ways for it. but yet know answer.
Posted
Updated 10-Aug-16 19:17pm
Comments
The Praveen Singh 10-Aug-16 6:18am    
you can not pass value in output parameter

Hi,

You don't return a value from your 2nd procedure.
Try modifying it to something like:

SQL
ALTER PROCEDURE GetLinage (
    @formname nvarchar,
    @linage  nvarchar OUTPUT
)
AS
 
SELECT @linage = Linage
FROM formslist
WHERE (formslist.Formname = @formname)

GO


... hope it helps.
 
Share this answer
 
Comments
m.r.m.40 13-Aug-16 1:24am    
Thanks, but it's not working.
hypermellow 15-Aug-16 4:14am    
Any detail on where it's not working?
... do you have an error message?
Check below Solution. So you don't have to change logic in inner SP.

Note: This solution will work only if
1. inner SP not contain below statement
2. It will give value of 1 row only, even SP returns multiple rows.
SQL
Insert Into #Table
EXEC ....


Script:
SQL
Alter PROCEDURE InsertLog
(
	@formName nvarchar,
	@buttonRout nvarchar,
	@buttonName nvarchar,
	@clickDateTime DateTime,
	@userCode bigint
)
 
AS
BEGIN
 
DECLARE @linage nvarchar(30)
Create Table #Result (linage nvarchar(30))

Insert Into #Result
EXEC #GetLinage @formName--, @linage  OUTPUT
 
Select @linage = linage From #Result

INSERT INTO 
LogTable(
	FormName,
	Linage,
	ButtonRout,
	ButtonName,
	ClickDateTime,
	UserCode
	)
Select	@FormName, @Linage, @ButtonRout, @ButtonName, @ClickDateTime, @UserCode
 
Share this answer
 

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