Solved

Finding UID of Inserted Record

Posted on 2006-07-13
10
369 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
Comment Utility
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
Comment Utility
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]
Comment Utility
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
 
LVL 4

Author Comment

by:Cyber-Drugs
Comment Utility
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
Comment Utility
alter table
  add  ComputedField as 'Material:'+ cast ( UID_FIELD as varchar(400) )

0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 4

Author Comment

by:Cyber-Drugs
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Two good answers, both work, points will be split.

Cheers guys!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Performance is the key factor for any successful data integration project, knowing the type of transformation that you’re using is the first step on optimizing the SSIS flow performance, by utilizing the correct transformation or the design alternat…
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

762 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now