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 |
programer
Posting Yak Master
221 Posts |
Posted - 2012-02-19 : 18:17:08
|
Hi,I would like to ask how to get SCOPE_IDENTITY from the table PodatkiNarocila and saved in the table tbl_Narocila of column PodatkiNarocilaIdALTER PROCEDURE dbo.InsertNarocila @PodatkiNarocilaId int, @ArtikelId int, @Count int, @Id intASBEGINSelect Id from tbl_PodatkiNarocilaSET @Id = SCOPE_IDENTITY(); INSERT dbo.tbl_Narocila (PodatkiNarocilaId, ArtikelId,Count) VALUES (@PodatkiNarocilaId, @ArtikelId,@Count) END |
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
programer
Posting Yak Master
221 Posts |
Posted - 2012-02-20 : 04:45:22
|
quote: Originally posted by tkizer You get the identity value directly after the insert into the table with the identity column. If you are looking just to get the current identity value of a table without doing an insert, then you would use DBCC CHECK_IDENT() instead. Please clarify for us what you are intending to do as your stored proc doesn't have the insert into tbl_PodatkiNarocila.Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/Subscribe to my blog
tbl_Narocila.PodatkiNarocilaId= Last Id from the table tbl_PodatkiNarocila |
 |
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-02-20 : 11:59:24
|
doesnt make any sense calling SCOPE_IDENTITY without insert. i think what you're after is grabbing last identity value generated?if yes..Select @Id = MAX(Id) from tbl_PodatkiNarocila... better approach would be capture id generated inline at place where insertion happens in tbl_PodatkiNarocila using OUTPUT clause------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|