accessing current written record

Ask a Question related to Microsoft SQL / MS SQL Server, Design and Development.

  1. #1

    Default Re: accessing current written record

    See @@IDENTITY and SCOPE_IDENTITY( ) in SQL Server Books Online.

    --
    HTH,
    Vyas, MVP (SQL Server)
    [url]http://vyaskn.tripod.com/[/url]
    What hardware is your SQL Server running on?
    [url]http://vyaskn.tripod.com/poll.htm[/url]




    "James Hall" <halljh@dshs.wa.gov> wrote in message
    news:014301c33f3a$5cee73d0$a501280a@phx.gbl...
    I am working on a multiple table insert. My master table
    has an id field that is an identity field. Before writing
    records to the related tables, I need to find out what the
    id is that was just created. I seem to remember being able
    to get to it by accessing a system cache - probably
    tempdb. I can't find my example - anybody know how to do
    this?

    Thank you,
    Jim.


    Narayana Vyas Kondreddi Guest

  2. Similar Questions and Discussions

    1. Either BOF or EOF is True, or the current record hasbeen deleted. Requested operation requires a current record
      Can anyone pls help? I am getting the following error when search my database. "ADODB.Field (0x800A0BCD Either BOF or EOF is True, or the...
    2. Accessing current user in Managed C++ Web Service?
      Hi Everyone, I created a managed c++ web service and I would like to access the current user. For instance, in a C# web service, you would...
    3. Accessing the current datasource row and column?
      How would i go about accessing a column in the currently binding row in a datagrids datasource the following code does not give me access to the...
    4. Query to insert into current record
      It sounds as though you are using one file (table), and you want all this activity to take place within the one file. You don't say where (what...
  3. #2

    Default Re: accessing current written record

    If you are performing a single insert you can use the SCOPE_IDENTITY()
    function to retrun the last identity value inserted within the same scope
    (proc, etc.)

    Ex:
    declare @ident int

    INSERT ...

    set @ident = SCOPE_IDENTITY()

    --Drew


    "James Hall" <halljh@dshs.wa.gov> wrote in message
    news:014301c33f3a$5cee73d0$a501280a@phx.gbl...
    > I am working on a multiple table insert. My master table
    > has an id field that is an identity field. Before writing
    > records to the related tables, I need to find out what the
    > id is that was just created. I seem to remember being able
    > to get to it by accessing a system cache - probably
    > tempdb. I can't find my example - anybody know how to do
    > this?
    >
    > Thank you,
    > Jim.

    Drew Seale Guest

  4. #3

    Default Re: accessing current written record

    DECLARE @id INT
    INSERT tbl(col_list) VALUES(val_list)
    SELECT @id = @@IDENTITY
    PRINT @id


    If using SQL Server 2000, replace @@IDENTITY with SCOPE_IDENTITY()

    (It's always helpful to post the version of SQL Server you're using; the
    solution can be different.)




    "James Hall" <halljh@dshs.wa.gov> wrote in message
    news:014301c33f3a$5cee73d0$a501280a@phx.gbl...
    > I am working on a multiple table insert. My master table
    > has an id field that is an identity field. Before writing
    > records to the related tables, I need to find out what the
    > id is that was just created. I seem to remember being able
    > to get to it by accessing a system cache - probably
    > tempdb. I can't find my example - anybody know how to do
    > this?
    >
    > Thank you,
    > Jim.

    Aaron Bertrand - MVP Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139