Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
vermorel
Starting Member
26 Posts |
Posted - 2006-02-08 : 15:55:38
|
| Basically I have a table with 2 fields UserId (string) and UserName (uniqueidentifer). The default value for UserId is newid().I can perform an insertion withINSERT INTO MyTable(UserName) VALUES ('Foo Bar');But I would like to retrieve the UserId that has just been created. How do I achieve that?Thanks in advance,Joannes |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2006-02-08 : 16:07:31
|
| declare @UserId uniqueidentiferselect @UserId = newid()INSERT INTO MyTable(UserId , UserName) select UserId , 'Foo Bar'select @UserId ==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
jhermiz
3564 Posts |
Posted - 2006-02-08 : 21:35:47
|
RETURN SCOPE_IDENTITY() Keeping the web experience alive -- [url]http://www.web-impulse.com[/url]RS Blog -- [url]http://weblogs.sqlteam.com/jhermiz[/url] |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-02-09 : 01:03:36
|
quote: Originally posted by jhermiz RETURN SCOPE_IDENTITY() Keeping the web experience alive -- [url]http://www.web-impulse.com[/url]RS Blog -- [url]http://weblogs.sqlteam.com/jhermiz[/url]
Thats for Identity column and not for uniqueidentifer columnNigel is correct so as thishttp://vyaskn.tripod.com/retrieve_guid_value_like_identity.htmMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|