dbTalk Databases Forums  

Returning the id of an inserted record

microsoft.public.sqlserver.clients microsoft.public.sqlserver.clients


Discuss Returning the id of an inserted record in the microsoft.public.sqlserver.clients forum.

Reply
 
Thread Tools Display Modes
  #11  
Old   
Kerry Moorman
 
Posts: n/a

Default RE: Returning the id of an inserted record - 02-29-2008 , 07:05 AM






Nathan,

After the insert statement you need to do a Select @@Identity statement to
retrieve the generated ID value.

Kerry Moorman


"Nathan Sokalski" wrote:

Quote:
I am writing an ASP.NET application, and am forced to use Access as my
database. I need a way to return the id (which is an AutoNumber field in the
table I am inserting into) of a record when I insert it. In SQL Server, I am
able to use a statement like the following:

INSERT INTO tablename (fieldnames) OUTPUT inserted.id VALUES(valuestoinsert)

Take note of the OUTPUT inserted.id part of this statement. This returns the
value of the field named 'id' for the record that was just inserted.
Unfortunately, this technique does not work in Access. Is there any way to
retrieve the id of the record that was just inserted when using Access? Any
help would be appreciated. Thanks.
--
Nathan Sokalski
njsokalski (AT) hotmail (DOT) com
http://www.nathansokalski.com/






Reply With Quote
  #12  
Old   
Andrew J. Kelly
 
Posts: n/a

Default Re: Returning the id of an inserted record - 02-29-2008 , 09:20 AM






I wasn't aware that @@Identity was also in Access so you may want to post
this question in an ACCESS news group not a SQL Server one. And for future
reference you should not use @@IDENTITY in SQL Server, you should use
SCOPE_IDENTITY() instead for this type of situation.

--
Andrew J. Kelly SQL MVP
Solid Quality Mentors


"Kerry Moorman" <KerryMoorman (AT) discussions (DOT) microsoft.com> wrote

Quote:
Nathan,

After the insert statement you need to do a Select @@Identity statement to
retrieve the generated ID value.

Kerry Moorman


"Nathan Sokalski" wrote:

I am writing an ASP.NET application, and am forced to use Access as my
database. I need a way to return the id (which is an AutoNumber field in
the
table I am inserting into) of a record when I insert it. In SQL Server, I
am
able to use a statement like the following:

INSERT INTO tablename (fieldnames) OUTPUT inserted.id
VALUES(valuestoinsert)

Take note of the OUTPUT inserted.id part of this statement. This returns
the
value of the field named 'id' for the record that was just inserted.
Unfortunately, this technique does not work in Access. Is there any way
to
retrieve the id of the record that was just inserted when using Access?
Any
help would be appreciated. Thanks.
--
Nathan Sokalski
njsokalski (AT) hotmail (DOT) com
http://www.nathansokalski.com/





Reply With Quote
  #13  
Old   
Andrew J. Kelly
 
Posts: n/a

Default Re: Returning the id of an inserted record - 02-29-2008 , 09:20 AM



I wasn't aware that @@Identity was also in Access so you may want to post
this question in an ACCESS news group not a SQL Server one. And for future
reference you should not use @@IDENTITY in SQL Server, you should use
SCOPE_IDENTITY() instead for this type of situation.

--
Andrew J. Kelly SQL MVP
Solid Quality Mentors


"Kerry Moorman" <KerryMoorman (AT) discussions (DOT) microsoft.com> wrote

Quote:
Nathan,

After the insert statement you need to do a Select @@Identity statement to
retrieve the generated ID value.

Kerry Moorman


"Nathan Sokalski" wrote:

I am writing an ASP.NET application, and am forced to use Access as my
database. I need a way to return the id (which is an AutoNumber field in
the
table I am inserting into) of a record when I insert it. In SQL Server, I
am
able to use a statement like the following:

INSERT INTO tablename (fieldnames) OUTPUT inserted.id
VALUES(valuestoinsert)

Take note of the OUTPUT inserted.id part of this statement. This returns
the
value of the field named 'id' for the record that was just inserted.
Unfortunately, this technique does not work in Access. Is there any way
to
retrieve the id of the record that was just inserted when using Access?
Any
help would be appreciated. Thanks.
--
Nathan Sokalski
njsokalski (AT) hotmail (DOT) com
http://www.nathansokalski.com/





Reply With Quote
  #14  
Old   
Andrew J. Kelly
 
Posts: n/a

Default Re: Returning the id of an inserted record - 02-29-2008 , 09:20 AM



I wasn't aware that @@Identity was also in Access so you may want to post
this question in an ACCESS news group not a SQL Server one. And for future
reference you should not use @@IDENTITY in SQL Server, you should use
SCOPE_IDENTITY() instead for this type of situation.

--
Andrew J. Kelly SQL MVP
Solid Quality Mentors


"Kerry Moorman" <KerryMoorman (AT) discussions (DOT) microsoft.com> wrote

Quote:
Nathan,

After the insert statement you need to do a Select @@Identity statement to
retrieve the generated ID value.

Kerry Moorman


"Nathan Sokalski" wrote:

I am writing an ASP.NET application, and am forced to use Access as my
database. I need a way to return the id (which is an AutoNumber field in
the
table I am inserting into) of a record when I insert it. In SQL Server, I
am
able to use a statement like the following:

INSERT INTO tablename (fieldnames) OUTPUT inserted.id
VALUES(valuestoinsert)

Take note of the OUTPUT inserted.id part of this statement. This returns
the
value of the field named 'id' for the record that was just inserted.
Unfortunately, this technique does not work in Access. Is there any way
to
retrieve the id of the record that was just inserted when using Access?
Any
help would be appreciated. Thanks.
--
Nathan Sokalski
njsokalski (AT) hotmail (DOT) com
http://www.nathansokalski.com/





Reply With Quote
  #15  
Old   
Andrew J. Kelly
 
Posts: n/a

Default Re: Returning the id of an inserted record - 02-29-2008 , 09:20 AM



I wasn't aware that @@Identity was also in Access so you may want to post
this question in an ACCESS news group not a SQL Server one. And for future
reference you should not use @@IDENTITY in SQL Server, you should use
SCOPE_IDENTITY() instead for this type of situation.

--
Andrew J. Kelly SQL MVP
Solid Quality Mentors


"Kerry Moorman" <KerryMoorman (AT) discussions (DOT) microsoft.com> wrote

Quote:
Nathan,

After the insert statement you need to do a Select @@Identity statement to
retrieve the generated ID value.

Kerry Moorman


"Nathan Sokalski" wrote:

I am writing an ASP.NET application, and am forced to use Access as my
database. I need a way to return the id (which is an AutoNumber field in
the
table I am inserting into) of a record when I insert it. In SQL Server, I
am
able to use a statement like the following:

INSERT INTO tablename (fieldnames) OUTPUT inserted.id
VALUES(valuestoinsert)

Take note of the OUTPUT inserted.id part of this statement. This returns
the
value of the field named 'id' for the record that was just inserted.
Unfortunately, this technique does not work in Access. Is there any way
to
retrieve the id of the record that was just inserted when using Access?
Any
help would be appreciated. Thanks.
--
Nathan Sokalski
njsokalski (AT) hotmail (DOT) com
http://www.nathansokalski.com/





Reply With Quote
  #16  
Old   
Andrew J. Kelly
 
Posts: n/a

Default Re: Returning the id of an inserted record - 02-29-2008 , 09:20 AM



I wasn't aware that @@Identity was also in Access so you may want to post
this question in an ACCESS news group not a SQL Server one. And for future
reference you should not use @@IDENTITY in SQL Server, you should use
SCOPE_IDENTITY() instead for this type of situation.

--
Andrew J. Kelly SQL MVP
Solid Quality Mentors


"Kerry Moorman" <KerryMoorman (AT) discussions (DOT) microsoft.com> wrote

Quote:
Nathan,

After the insert statement you need to do a Select @@Identity statement to
retrieve the generated ID value.

Kerry Moorman


"Nathan Sokalski" wrote:

I am writing an ASP.NET application, and am forced to use Access as my
database. I need a way to return the id (which is an AutoNumber field in
the
table I am inserting into) of a record when I insert it. In SQL Server, I
am
able to use a statement like the following:

INSERT INTO tablename (fieldnames) OUTPUT inserted.id
VALUES(valuestoinsert)

Take note of the OUTPUT inserted.id part of this statement. This returns
the
value of the field named 'id' for the record that was just inserted.
Unfortunately, this technique does not work in Access. Is there any way
to
retrieve the id of the record that was just inserted when using Access?
Any
help would be appreciated. Thanks.
--
Nathan Sokalski
njsokalski (AT) hotmail (DOT) com
http://www.nathansokalski.com/





Reply With Quote
  #17  
Old   
Andrew J. Kelly
 
Posts: n/a

Default Re: Returning the id of an inserted record - 02-29-2008 , 09:20 AM



I wasn't aware that @@Identity was also in Access so you may want to post
this question in an ACCESS news group not a SQL Server one. And for future
reference you should not use @@IDENTITY in SQL Server, you should use
SCOPE_IDENTITY() instead for this type of situation.

--
Andrew J. Kelly SQL MVP
Solid Quality Mentors


"Kerry Moorman" <KerryMoorman (AT) discussions (DOT) microsoft.com> wrote

Quote:
Nathan,

After the insert statement you need to do a Select @@Identity statement to
retrieve the generated ID value.

Kerry Moorman


"Nathan Sokalski" wrote:

I am writing an ASP.NET application, and am forced to use Access as my
database. I need a way to return the id (which is an AutoNumber field in
the
table I am inserting into) of a record when I insert it. In SQL Server, I
am
able to use a statement like the following:

INSERT INTO tablename (fieldnames) OUTPUT inserted.id
VALUES(valuestoinsert)

Take note of the OUTPUT inserted.id part of this statement. This returns
the
value of the field named 'id' for the record that was just inserted.
Unfortunately, this technique does not work in Access. Is there any way
to
retrieve the id of the record that was just inserted when using Access?
Any
help would be appreciated. Thanks.
--
Nathan Sokalski
njsokalski (AT) hotmail (DOT) com
http://www.nathansokalski.com/





Reply With Quote
  #18  
Old   
Andrew J. Kelly
 
Posts: n/a

Default Re: Returning the id of an inserted record - 02-29-2008 , 09:20 AM



I wasn't aware that @@Identity was also in Access so you may want to post
this question in an ACCESS news group not a SQL Server one. And for future
reference you should not use @@IDENTITY in SQL Server, you should use
SCOPE_IDENTITY() instead for this type of situation.

--
Andrew J. Kelly SQL MVP
Solid Quality Mentors


"Kerry Moorman" <KerryMoorman (AT) discussions (DOT) microsoft.com> wrote

Quote:
Nathan,

After the insert statement you need to do a Select @@Identity statement to
retrieve the generated ID value.

Kerry Moorman


"Nathan Sokalski" wrote:

I am writing an ASP.NET application, and am forced to use Access as my
database. I need a way to return the id (which is an AutoNumber field in
the
table I am inserting into) of a record when I insert it. In SQL Server, I
am
able to use a statement like the following:

INSERT INTO tablename (fieldnames) OUTPUT inserted.id
VALUES(valuestoinsert)

Take note of the OUTPUT inserted.id part of this statement. This returns
the
value of the field named 'id' for the record that was just inserted.
Unfortunately, this technique does not work in Access. Is there any way
to
retrieve the id of the record that was just inserted when using Access?
Any
help would be appreciated. Thanks.
--
Nathan Sokalski
njsokalski (AT) hotmail (DOT) com
http://www.nathansokalski.com/





Reply With Quote
  #19  
Old   
Andrew J. Kelly
 
Posts: n/a

Default Re: Returning the id of an inserted record - 02-29-2008 , 09:20 AM



I wasn't aware that @@Identity was also in Access so you may want to post
this question in an ACCESS news group not a SQL Server one. And for future
reference you should not use @@IDENTITY in SQL Server, you should use
SCOPE_IDENTITY() instead for this type of situation.

--
Andrew J. Kelly SQL MVP
Solid Quality Mentors


"Kerry Moorman" <KerryMoorman (AT) discussions (DOT) microsoft.com> wrote

Quote:
Nathan,

After the insert statement you need to do a Select @@Identity statement to
retrieve the generated ID value.

Kerry Moorman


"Nathan Sokalski" wrote:

I am writing an ASP.NET application, and am forced to use Access as my
database. I need a way to return the id (which is an AutoNumber field in
the
table I am inserting into) of a record when I insert it. In SQL Server, I
am
able to use a statement like the following:

INSERT INTO tablename (fieldnames) OUTPUT inserted.id
VALUES(valuestoinsert)

Take note of the OUTPUT inserted.id part of this statement. This returns
the
value of the field named 'id' for the record that was just inserted.
Unfortunately, this technique does not work in Access. Is there any way
to
retrieve the id of the record that was just inserted when using Access?
Any
help would be appreciated. Thanks.
--
Nathan Sokalski
njsokalski (AT) hotmail (DOT) com
http://www.nathansokalski.com/





Reply With Quote
  #20  
Old   
Andrew J. Kelly
 
Posts: n/a

Default Re: Returning the id of an inserted record - 02-29-2008 , 09:20 AM






I wasn't aware that @@Identity was also in Access so you may want to post
this question in an ACCESS news group not a SQL Server one. And for future
reference you should not use @@IDENTITY in SQL Server, you should use
SCOPE_IDENTITY() instead for this type of situation.

--
Andrew J. Kelly SQL MVP
Solid Quality Mentors


"Kerry Moorman" <KerryMoorman (AT) discussions (DOT) microsoft.com> wrote

Quote:
Nathan,

After the insert statement you need to do a Select @@Identity statement to
retrieve the generated ID value.

Kerry Moorman


"Nathan Sokalski" wrote:

I am writing an ASP.NET application, and am forced to use Access as my
database. I need a way to return the id (which is an AutoNumber field in
the
table I am inserting into) of a record when I insert it. In SQL Server, I
am
able to use a statement like the following:

INSERT INTO tablename (fieldnames) OUTPUT inserted.id
VALUES(valuestoinsert)

Take note of the OUTPUT inserted.id part of this statement. This returns
the
value of the field named 'id' for the record that was just inserted.
Unfortunately, this technique does not work in Access. Is there any way
to
retrieve the id of the record that was just inserted when using Access?
Any
help would be appreciated. Thanks.
--
Nathan Sokalski
njsokalski (AT) hotmail (DOT) com
http://www.nathansokalski.com/





Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.