> I know this has been asked before a while back, but I can find the
> mail which covered it, so here's the question.
>
> I add a record which is using a "uniqueidentifier" as the key, how can
> I then get the value of that field, without having to do a search on
> the rest of the data I've just added (which ain't unique enough)?
>
> I seem to remember that you used some SQL @somethingOrOther to
> reference it, but can pin down a solution.

@@identity returns the inserted identity field, but it must be done within
the same query - I tend to use;

set nocount on
insert into MYTABLE (myField)
values ('myValue')
select @@identity as ID
set nocount off

The returned ID is then the new identity

You may want to look at Triggers though, as this saves a bit of code on your
end and SQL Server automatically sends the new ID at you

Philip Arnold
ASP Multimedia Limited
T: +44 (0)20 8680 1133

"Websites for the real world"

**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.
**********************************************************************


------------------------------------------------------------------------------------------------
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists or send a message 
with 'unsubscribe' in the body to [EMAIL PROTECTED]

Reply via email to