Login    Forum    Search    FAQ   Blog

Board index » Server Side Development » SQL




 Page 1 of 1 [ 3 posts ] 



Author Message
 Post subject: uniqueidentifier column of da last insertd row
 Post Posted: Thu Nov 19, 2009 7:01 am 
Offline

Joined: Sat Feb 21, 2009 1:05 pm
Posts: 66
Hi,
I m havin a tab primary column of da uniqueidentifier type. Whenever I
inserted a new row 2 da table, I ned to return da val of da
uniqueidentifier column of da last-inserted row. Please do tell me how
could i get the column value?

I know dat if a column was of da int (identity), then 2 get da
last-inserted identity val , I could use @@IDENTITY. howevr in ma
case, da primary column is of da uniqueidentifire type, nd I do not
know how 2 do.

Thanks,

_________________
If your wife wants to learn to drive, don't stand in her way.


Top 
 Post subject: Re: uniqueidentifier column of da last insertd row
 Post Posted: Thu Nov 19, 2009 7:01 am 
Offline

Joined: Sat Feb 21, 2009 11:06 am
Posts: 1794
You could use da o/p clause of da insert statement.

Code:
create table TestTable (id uniqueidentifier, descr varchar(10))
go
insert into TestTable output inserted.id  values(newid(),'abcd')
go


If u want 2 get the o/p in 2 a variable, you could use a table
variable just like this:

Code:
declare @outputTable table ( id uniqueidentifier);
insert into TestTable output inserted.id into @outputTable values(newid(),'abcd')
select * from @outputTable


Top 
 Post subject: Re: uniqueidentifier column of da last insertd row
 Post Posted: Thu Nov 19, 2009 7:01 am 
Offline

Joined: Sat Feb 21, 2009 1:08 pm
Posts: 549
Code:
DECLARE @u UNIQUEIDENTIFIER

SET @u = NEWID()



INSERT ...
SELECT @u, ... FROM ...


Top 
Display posts from previous:  Sort by  
 
 Page 1 of 1 [ 3 posts ] 




Board index » Server Side Development » SQL


Who is online

Users browsing this forum: No registered users and 2 guests

 
 

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron