Link to home
Start Free TrialLog in
Avatar of Cyber-Drugs
Cyber-DrugsFlag for United Kingdom of Great Britain and Northern Ireland

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_RECORD

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!
Avatar of Ved Prakash Agrawal
Ved Prakash Agrawal
Flag of India image

you need to update the fields after insert.
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.


Avatar of Cyber-Drugs

ASKER

OK, and what code is used to get the unique value of the Inserted Record?
Avatar of Guy Hengel [angelIII / a3]
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?

angelIII

The value will never change, it is done once, and that is it. :)
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
I only just noticed your post after I made mine AngelIII.

Will try your code out first.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of DireOrbAnt
DireOrbAnt

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.
Two good answers, both work, points will be split.

Cheers guys!