Re: INSERT

From: Vishal Parkar (REMOVE_THIS_vgparkar_at_yahoo.co.in)
Date: 02/21/04

  • Next message: Charles Coggins: "SQL errors on start-up"
    Date: Sat, 21 Feb 2004 13:07:07 +0530
    
    

    hi darren,

    >>When they are done filling this form they go to a page
    with links to the other pages. I need to be able to pull
    the identity column parameter for that workorder to use
    as a link to the other pages. <<

    Look at the function scope_identity() in books online. This function returns the last IDENTITY
    value inserted into an IDENTITY column. After running INSERT statement into the table run
    SCOPE_IDENTITY()

    Ex:
    declare @x int
    CREATE TABLE TY (
       Y_id int IDENTITY(1,1)PRIMARY KEY,
       Y_name varchar(20) NULL)
    go
    INSERT TY (Y_name) VALUES ('x')
    INSERT TY (Y_name) VALUES ('y')
    go
    SET @x=SCOPE_IDENTITY() --@x will consist of last identity value inserted into table TY

    -- 
    Vishal Parkar
    vgparkar@yahoo.co.in
    

  • Next message: Charles Coggins: "SQL errors on start-up"

    Relevant Pages

    • Re: Getting at @@IDENTITY
      ... int ID //identity column ... char 10 fld1 ... Now I need the identity column from that insert. ...
      (microsoft.public.sqlserver.ce)
    • Re: Few queries
      ... the type of identity column which can be tinyint, smallint, int, bigint, ... You get error message if the identity value greater than ... > C] Can we have DML statements in the body of function? ...
      (microsoft.public.sqlserver.programming)
    • Re: Is this an MSSQL bug?
      ... > I have the following query on MSSQL 2000. ... > declare @t table(i int identity, j int, k int) ... > An explicit value for the identity column in table '@t' can only be ...
      (microsoft.public.sqlserver.programming)
    • RE: ASP.NET and @@IDENTITY
      ... INSERT INTO SomeTable (IntValue, SomeTextValue) ... SqlConnection conn = new SqlConnection; ... //Assumes an int type for the IDENTITY column ...
      (microsoft.public.dotnet.framework.adonet)
    • Re: Choice of Primary Key/Identity Fields
      ... > That means it's not guaranteed unique (an identity does not guarantee ... > colref_id int, ... > Even if this is the case not having a unique index on an identity column ...
      (microsoft.public.sqlserver.programming)