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
 GET IDENTITY FROM TABLE

Author  Topic 

mellamokb
Starting Member

39 Posts

Posted - 2006-03-16 : 19:03:43
How do i get identity from stored procedure? I CANNOT GET THE ID I CANNOT RETURN ANYTHING AT ALL! WHY?

This is last three lines of stored procedure

SELECT ID = SCOPE_IDENTITY()
RETURN
GO

I get ABSOLUTELY nothing I can't get anything to come back from by stored procedure to my ASP page. I have a "RETURN_VALUE" parameter, that's not the problem. There's something really stupid about this stored procedure that since I've inserted records into a table then from that point on I cannot return ANYTHING! WHYYYYYY???

Sorry, I am SO VERY frustrated. Can anyone help me?

mellamokb

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2006-03-16 : 19:06:46
You need to put the identity value into a variable and output it using an output parameter.

CREATE PROC ...
(..., @id int OUTPUT)
AS
...
SELECT @id = SCOPE_IDENTITY()
RETURN
GO


Tara Kizer
aka tduggan
Go to Top of Page

mellamokb
Starting Member

39 Posts

Posted - 2006-03-16 : 23:02:21
Thank you very much! It works great! I just had to look up online how to use output parameters with ASP. Thank you very much for your help; I was really frustrated but now it works =D.

mellamokb
Go to Top of Page

druer
Constraint Violating Yak Guru

314 Posts

Posted - 2006-03-17 : 09:29:21
If you don't want to use output parameters you'd just need to add the following line:
select @id
after you assign it to the scope_identity() value. The select you have is an assignment which returns nothing but a message that says "1 Rows affected." If you want the actual value returned you need to select it, per above. Output parameters are nicer if you can code for them, as you can also get the values assigned/use them from other stored procedures, queries.
Go to Top of Page
   

- Advertisement -