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
 SP value transfer

Author  Topic 

messi
Starting Member

47 Posts

Posted - 2008-09-09 : 19:29:03
i made 2 sp

sp1:
create proc one
(@st int,@en int)
As
insert source (start,endv)
values(@st,@en)

i want to use @st&@en values in another sp
can i do that...

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-09-09 : 19:30:38
Yes. You've got them as input parameters, so your application already knows the values. Just pass the values to the other stored procedure.

You should also be aware of OUTPUT parameters.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

messi
Starting Member

47 Posts

Posted - 2008-09-10 : 08:54:25
thanks ,but how i can do this with code..(pass the values to the other stored procedure. )
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-09-10 : 08:59:16
Are you calling both the sp from the same program ? You would have the value of @st and @en to pass to the 1st SP, just use it to pass to the 2nd SP.

exec one @st, @en

exec two @st, @en


What is your issue here ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

sunil
Constraint Violating Yak Guru

282 Posts

Posted - 2008-09-10 : 09:00:00
Not sure If I understand you. You can easily pass parameters from one SP to another. See code below:

create proc SP2
(@st int,@en int)
AS
BEGIN
--DO something using input parameters
END

create proc one
(@st int,@en int)
As
BEGIN
insert source (start,endv)
values(@st,@en)
exec SP2 @st,@en
END
Go to Top of Page

messi
Starting Member

47 Posts

Posted - 2008-09-10 : 09:12:23
Thanks all i will try it
and replay
Go to Top of Page

messi
Starting Member

47 Posts

Posted - 2008-09-10 : 10:18:11
i tried but it did nothing
so i put image to give you more help

Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-09-10 : 10:35:51
how are these 2 SP invoke ?
adds will exec sourceins ?
or sourceins will exec adds ?
or both are exec from another SP or your application ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

messi
Starting Member

47 Posts

Posted - 2008-09-10 : 10:46:42
No ,
sourceins will exec from my application
adds will exec from a trigger

look i will tell you my idea :

i will enter 2 numbers in my application
this 2 num will saved by (sp sourceins) in source table
then i made trigger: when i insert 2 num in source table the trigger will exec (adds SP)
so
i need to store this 2 num values in (adds SP) in here(look image)
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-09-10 : 11:05:35
it is in the inserted table


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

messi
Starting Member

47 Posts

Posted - 2008-09-10 : 17:11:39
Sorry i don't understand ..
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-09-11 : 01:07:30
your stored procedure adds is basically execute in the trigger. When trigger executes, there are 2 tables available which is the inserted and deleted table.

see http://msdn.microsoft.com/en-us/library/aa258254.aspx

quote:
A few special tables are used in CREATE TRIGGER statements:

* deleted and inserted are logical (conceptual) tables. They are structurally similar to the table on which the trigger is defined, that is, the table on which the user action is attempted, and hold the old values or new values of the rows that may be changed by the user action


the inserted table will contains rows (note : maybe more than 1 rows) of the inserted value. The value you want will be available in the inserted table


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -