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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

stored procedure/Identity field

Status
Not open for further replies.

vbmorton

Technical User
Dec 27, 2004
44
US
Was wonderin if anyone can help me, im trying to retrieve the identity value of a field x while doing an add to the table, in my vb6 code i call this stored procedure using a class module, how could i retrieve the value of my identity (field x) back, its not part of my add to the table its just in the table as counter.
any ideas?




Code:
CREATE PROCEDURE [sp_Projectnoteadd]
	(@projectno_1 	[int],
	 @notedate_2 	[datetime],
	 @note_3 	[text])

AS INSERT INTO [dbo].[ProjectNotes] 
	 ( [projectno],
	 [notedate],
	 [note]) 
 
VALUES 
	( @projectno_1,
	 @notedate_2,
	 @note_3)
 
change the stored proc to be
Code:
CREATE PROCEDURE [sp_Projectnoteadd]
    (@projectno_1     [int],
     @notedate_2     [datetime],
     @note_3     [text],
     @po_MyIdentity bigint OUTPUT)

AS INSERT INTO [dbo].[ProjectNotes] 
     ( [projectno],
     [notedate],
     [note]) 
 
VALUES 
    ( @projectno_1,
     @notedate_2,
     @note_3)
SELECT @po_MyIdentity= SCOPE_IDENTITY()
You will need to add a new parameter to hold the new return field, then the result will be in the additional parameter.


"I'm living so far beyond my income that we may almost be said to be living apart
 
hmckillop,

Thanks for responding, I tried using that.. and it tells me that scope_identity() is an invalid function?
 
I would use ident_current('tablename') instead of @@IDENTITY OR SCOPE_IDENTITY
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top