Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Getting a next number value
Message
 
À
10/10/2007 05:48:58
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Autre
Divers
Thread ID:
01259689
Message ID:
01259939
Vues:
14
>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.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform