Solved

Finding UID of Inserted Record

Posted on 2006-07-13
10
372 Views
Last Modified: 2008-02-01
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!
0
Comment
Question by:Cyber-Drugs
  • 5
  • 2
  • 2
  • +1
10 Comments
 
LVL 11

Expert Comment

by:Ved Prakash Agrawal
ID: 17099959
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.


0
 
LVL 4

Author Comment

by:Cyber-Drugs
ID: 17099971
OK, and what code is used to get the unique value of the Inserted Record?
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 17100016
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?

0
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 
LVL 4

Author Comment

by:Cyber-Drugs
ID: 17100034
angelIII

The value will never change, it is done once, and that is it. :)
0
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 250 total points
ID: 17100220
alter table
  add  ComputedField as 'Material:'+ cast ( UID_FIELD as varchar(400) )

0
 
LVL 4

Author Comment

by:Cyber-Drugs
ID: 17100271
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
0
 
LVL 4

Author Comment

by:Cyber-Drugs
ID: 17100277
I only just noticed your post after I made mine AngelIII.

Will try your code out first.
0
 
LVL 26

Assisted Solution

by:DireOrbAnt
DireOrbAnt earned 250 total points
ID: 17100638
Change your Update to:
UPDATE dbo.tblModule
SET NodeName = 'Module:'+CAST(SCOPE_IDENTITY() AS VARCHAR(10))
WHERE UID = SCOPE_IDENTITY()
0
 
LVL 26

Expert Comment

by:DireOrbAnt
ID: 17100700
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.
0
 
LVL 4

Author Comment

by:Cyber-Drugs
ID: 17106533
Two good answers, both work, points will be split.

Cheers guys!
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question