Hello !
I just can't access @.@.IDENTITY in my requests !
Here is my stored procedure : (I removed a few lines for clarity)
set ANSI_NULLSONset QUOTED_IDENTIFIERONGOALTER PROCEDURE [dbo].[AssignerLicence](@.Apprenantint = 0)ASBEGINSET NOCOUNT ON;DECLARE @.NBLICENCESintDECLARE @.COMMANDEIDintDECLARE @.LICENCEIDintSET @.NBLICENCES = (SELECTSUM(commande_licences_reste)FROM CommandeWHERE commande_valide = 1)IF@.NBLICENCES > 0BEGINUPDATE CommandeSET commande_licences_reste = (commande_licences_reste - 1)WHERE commande_id =(SELECT TOP 1 C_min.commande_idFROM CommandeAS C_minWHERE C_min.commande_licences_reste > 5ORDER BY C_min.commande_licences_resteASC,C_min.commande_dateASC);SET @.COMMANDEID =@.@.IDENTITYINSERT INTO Licence (licence_date_debut, commande_id)VALUES (GETDATE(), @.COMMANDEID)SET @.LICENCEID =@.@.IDENTITYUPDATE ApprenantSET licence_id = @.LICENCEIDWHERE apprenant_id = @.ApprenantENDEND
But it always throws an error saying that I can't insert null into commande_id (basically, I think @.@.IDENTITY isn't executed at all)
Any idea why it doen't works ?
Thanks !
@.@.IDENTITY returns the last identity value that the currently executing statement created. Since all you are doing with CommandeID is updating, you can't use @.@.Identity. You need to rework your code similar to the following:
SELECT @.COMMANDEID = (SELECT TOP 1 C_min.commande_idFROM CommandeAS C_minWHERE C_min.commande_licences_reste > 5ORDER BY C_min.commande_licences_resteASC,C_min.commande_dateASC);UPDATE CommandeSET commande_licences_reste = (commande_licences_reste - 1)WHERE commande_id = @.COMMANDEIDThen test if it works.
No comments:
Post a Comment