I want to use @@indentity Scalar variable in Stored procedure
-
Hy to All; I want to use two insert statement in one stored procedure I have Two Tables "Activitity" (ActivitityId as a primery key) and "TODo" Second Table (TODOId as a primery) and (ActivitityId as a foriegn key) .... So when a value insert into "Activitity" Table ,I want to insert its primery key into "TODO" Table as Foriegn key in a single Stored procedure... So for this purpose I want to use @@indentity variable how can I use @@indentity variable in my stored procedure....
-
Hy to All; I want to use two insert statement in one stored procedure I have Two Tables "Activitity" (ActivitityId as a primery key) and "TODo" Second Table (TODOId as a primery) and (ActivitityId as a foriegn key) .... So when a value insert into "Activitity" Table ,I want to insert its primery key into "TODO" Table as Foriegn key in a single Stored procedure... So for this purpose I want to use @@indentity variable how can I use @@indentity variable in my stored procedure....
if you have a column set as identity you can use SCOPE_IDENTITY() DECLARE @MyNewId INT SET @MyNewId = SCOPE_IDENTITY()
-
Hy to All; I want to use two insert statement in one stored procedure I have Two Tables "Activitity" (ActivitityId as a primery key) and "TODo" Second Table (TODOId as a primery) and (ActivitityId as a foriegn key) .... So when a value insert into "Activitity" Table ,I want to insert its primery key into "TODO" Table as Foriegn key in a single Stored procedure... So for this purpose I want to use @@indentity variable how can I use @@indentity variable in my stored procedure....
So store the @@Identity or Scope_Identity() in a variable directly after inserting the activity record and use it in the second insert for todo, there you have your relationship
Never underestimate the power of human stupidity RAH
-
Hy to All; I want to use two insert statement in one stored procedure I have Two Tables "Activitity" (ActivitityId as a primery key) and "TODo" Second Table (TODOId as a primery) and (ActivitityId as a foriegn key) .... So when a value insert into "Activitity" Table ,I want to insert its primery key into "TODO" Table as Foriegn key in a single Stored procedure... So for this purpose I want to use @@indentity variable how can I use @@indentity variable in my stored procedure....
Even you can go ahead with OUTPUT.INSERTED e.g.
insert into Activitity
output inserted.ActivitityId into TODo(ActivitityId)
values(1,'somerecord')select * from TODo Output:
TODOId ActivitityId
1 1:)
Niladri Biswas
-
Even you can go ahead with OUTPUT.INSERTED e.g.
insert into Activitity
output inserted.ActivitityId into TODo(ActivitityId)
values(1,'somerecord')select * from TODo Output:
TODOId ActivitityId
1 1:)
Niladri Biswas
Now that's cool, I was not aware INSERTED worked for an ordinary insert statement, I thought it was only for triggers. Now to go play, I wonder is UPDATED works as well
Never underestimate the power of human stupidity RAH
-
Now that's cool, I was not aware INSERTED worked for an ordinary insert statement, I thought it was only for triggers. Now to go play, I wonder is UPDATED works as well
Never underestimate the power of human stupidity RAH
Hi Mycroft, You are right. It is applicable for Insert, Update & Delete. Have a look a) OUTPUT Clause (Transact-SQL)[^] b) SQL SERVER – 2005 – OUTPUT Clause Example and Explanation with INSERT, UPDATE, DELETE[^]
Niladri Biswas