Solved

How to get lastest incremented UNIQUEIDENTIFIER?

Posted on 2004-08-24
4
216 Views
Last Modified: 2012-05-05
Hello Everyone!
       As last inserted value can be got through "Select @@Identifier" if we are using INTEGER datatype but what if we use UNIQUEIDENTIFIER datatype, how do we get last inserted value?

                                                                       Thanx,

                                                                       Adnan
0
Comment
Question by:kamran_khan
4 Comments
 
LVL 11

Accepted Solution

by:
ram2098 earned 500 total points
ID: 11878604
There isn't a way to get the value of a uniqueidentifier column after an insert. You can get it before the insert, however, by using the below code.

DECLARE @GUID uniqueidentifier
SET @GUID = NEWID()
INSERT Item VALUES (@GUID,'Yak Hoof')
0
 
LVL 4

Expert Comment

by:davehilditch
ID: 11880320
And additonally, you shouldn't really use @@IDENTITY in the first place, as if you have a trigger on the table which then inserts to another table you will receive the wrong value.  For identity columns, you should use scope_identity() instead.

Dave Hilditch.
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

815 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

11 Experts available now in Live!

Get 1:1 Help Now