Cyber-Drugs
asked on
Finding UID of Inserted Record
Hi guys,
Is it possible to have in an INSERT statement, an extra field which is something like this:
'Material:'+@UID_OF_THIS_R ECORD
So basically, mixing text, with the INT, UID of the record being Inserted, or would I need to do it in an UPDATE after the INSERT? If so, how would I know what the UID of the Inserted record is?
Cheers guys!
Is it possible to have in an INSERT statement, an extra field which is something like this:
'Material:'+@UID_OF_THIS_R
So basically, mixing text, with the INT, UID of the record being Inserted, or would I need to do it in an UPDATE after the INSERT? If so, how would I know what the UID of the Inserted record is?
Cheers guys!
ASKER
OK, and what code is used to get the unique value of the Inserted Record?
will the value ever change once the record is created?
-> if no, make this a computed field and not a "true" field.
-> yes
is it identity or uniqueidentified?
-> if no, make this a computed field and not a "true" field.
-> yes
is it identity or uniqueidentified?
ASKER
angelIII
The value will never change, it is done once, and that is it. :)
The value will never change, it is done once, and that is it. :)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Would something like this work?
INSERT INTO dbo.tblModule
(
DeviceID,
ModuleCatID,
SlotID,
[Serial Number],
Module_FL,
SAP_EQ
) VALUES (
@DeviceUID,
@ModuleCatUID,
@SlotUID,
@serial,
@data,
@equipment
)
UPDATE dbo.tblModule
SET NodeName = 'Module:'+@@IDENTITY
WHERE UID = @@IDENTITY
INSERT INTO dbo.tblModule
(
DeviceID,
ModuleCatID,
SlotID,
[Serial Number],
Module_FL,
SAP_EQ
) VALUES (
@DeviceUID,
@ModuleCatUID,
@SlotUID,
@serial,
@data,
@equipment
)
UPDATE dbo.tblModule
SET NodeName = 'Module:'+@@IDENTITY
WHERE UID = @@IDENTITY
ASKER
I only just noticed your post after I made mine AngelIII.
Will try your code out first.
Will try your code out first.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If you are expecting bigint as the ID, cast as VARCHAR(19).
AngelIII's method is much more integrated. Unsure about speed for a computed field though.
AngelIII's method is much more integrated. Unsure about speed for a computed field though.
ASKER
Two good answers, both work, points will be split.
Cheers guys!
Cheers guys!
when you insert the records then you can get the unique value which is inserted.
and then you can update this value in the record which is inserted.