SQL task & @@IDENTITY

  • I'm developing a DTS package in SQLserver 2000. I have a simple problem...or so I thought!

    I have an Execute SQL Task;

    INSERT INTO MyTable([name], phone, fax, email)

    VALUES('john','123-6321','123-5321','john@place.com')

    This INSERTs a new record into MyTable.

    I also want the row ID of the just inserted record. So I added this code which I've used before in asp pages.

    SELECT ID = @@IDENTITY Then I assigned ID to a Global var.

    I've also tried SCOPE_IDENTITY() and IDENT_CURRENT().

    I've seen this done in 2005 SSIS but I'm not getting anything!

    Has anyone run into this?:angry:

    ********UPDATE*************

    I found this same topic on this forum from 2006...

    http://www.sqlservercentral.com/Forums/Topic254982-19-1.aspx

    Doesn't sound like theres a good way around it...

    Microsoft strikes again...


    A.S.

    MCSE, ASE, DBA

    Webmaster

    Applications Developer

  • you'd need a declare @id int

    select @id = scope_identity()

    however I'm not sure how you plan on using this in DTS or your Execute SQL task. Maybe if you explain what you want to do, we can help.

  • Heh... one of the many reasons I don't use DTS...

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply