Re: trying to copy the autonumber from one table to the next
From: Peter Row (***.off_at_bastard_spammers.com)
Date: 12/06/04
- Next message: sparks_at_somewhere.net: "Re: trying to copy the autonumber from one table to the next"
- Previous message: Faustino Dina: "Returning an array in a property get returns a copy. How to get a reference?"
- In reply to: Brian Brown: "RE: trying to copy the autonumber from one table to the next"
- Next in thread: sparks_at_somewhere.net: "Re: trying to copy the autonumber from one table to the next"
- Reply: sparks_at_somewhere.net: "Re: trying to copy the autonumber from one table to the next"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 6 Dec 2004 14:31:24 -0000
Hi,
Actually you can say just SELECT @@IDENTITY.
To prove this just run the line in query analyser. Running it on it's own
you get an unnamed column with the value NULL.
The problem with the original post is more likely that the original poster
is not running the INSERT and the @@IDENTITY
select in the same command. Therefore @@IDENTITY will be null, if you ran it
within the command as the INSERT you would
get a number back.
Bye,
Pete
"Brian Brown" <BrianBrown@discussions.microsoft.com> wrote in message
news:92CBD23D-076A-4A09-BDD8-BA786B68DA02@microsoft.com...
> Sparks,
>
> You cannot call just SELECT @@IDENTITY. Sql has no way of knowing what
> record you want to look for. Would it be possible for you to write a
> stored
> proc and send it your parameters? Then you could use a return statement
> in
> the stored proc to return the ID of the inserted record and then grab it
> using ExecuteScalar(). This is a lot more efficient and reliable all the
> way
> around.
>
> Good Luck!
>
- Next message: sparks_at_somewhere.net: "Re: trying to copy the autonumber from one table to the next"
- Previous message: Faustino Dina: "Returning an array in a property get returns a copy. How to get a reference?"
- In reply to: Brian Brown: "RE: trying to copy the autonumber from one table to the next"
- Next in thread: sparks_at_somewhere.net: "Re: trying to copy the autonumber from one table to the next"
- Reply: sparks_at_somewhere.net: "Re: trying to copy the autonumber from one table to the next"
- Messages sorted by: [ date ] [ thread ]