Results 1 to 4 of 4

Thread: @@identity not returning any value [resolved]

  1. #1

    Thread Starter
    Hyperactive Member thebloke's Avatar
    Join Date
    May 2003
    Posts
    358

    @@identity not returning any value [resolved]

    Can any one see what's wrong with this? I'm calling it from an asp page. It's inserting the value but not returning anything in the recordset......

    Code:
    CREATE PROCEDURE spVan_Start AS
    
    insert into tblVan_counter (q1) values (1)
    
    select @@identity
    GO
    Last edited by thebloke; May 20th, 2005 at 10:10 AM. Reason: resolved
    The Bloke
    www.blokeinthekitchen.com
    making cooking cool for blokes

  2. #2
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: @@identity not returning any value

    Add a Set NoCount On statement before the Insert statement. Or better yet, return the new identity value in an Output parameter and eliminate the overhead of a recordset.

  3. #3
    Fanatic Member Blade's Avatar
    Join Date
    Jan 1999
    Location
    Stoke-on-Trent, UK
    Posts
    527

    Re: @@identity not returning any value

    If you're using SQL Server 2000 try returning:
    Code:
    SELECT SCOPE_IDENTITY()
    instead as @@IDENTITY is global and will not necessarily return you the ID of the table you just inserted into (especially if you have triggers on that table that insert into another table!)

  4. #4

    Thread Starter
    Hyperactive Member thebloke's Avatar
    Join Date
    May 2003
    Posts
    358

    Resolved Re: @@identity not returning any value

    combined both and it works:

    Code:
    CREATE PROCEDURE spVan_Start AS
    
    SET NoCount On
    
    insert into tblVan_counter (q1) values (1)
    
    select SCOPE_IDENTITY()
    GO
    Thanks guys
    The Bloke
    www.blokeinthekitchen.com
    making cooking cool for blokes

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width