Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Getting a next number value
Message
 
To
10/10/2007 05:48:58
General information
Forum:
Microsoft SQL Server
Category:
Other
Miscellaneous
Thread ID:
01259689
Message ID:
01259939
Views:
15
>Hello Jerry!
>
>I use code:
>
>Create PROCEDURE [dbo].[insert_mytable]
>@l_1 int, @l_2 varchar(20)
>AS
>Insert into cred.dbo.mytable (field1,field2) VALUES (@l_1,@l2)
>Select @@IDENTITY as 'Identity'
>
>
>Sergey.

NEVER use @@IDENTITY, If you have trigger that affect other table that have IDENTITY field you will get wrong information.
Use SCOPE_IDENTITY() function instead.
Create PROCEDURE [dbo].[insert_mytable]
       @l_1 int,
       @l_2 varchar(20)
AS
   Insert into cred.dbo.mytable (field1,field2) VALUES (@l_1, @l2)
   Select SCOPE_IDENTITY() as 'Identity'
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform