Comment puis-je définir la valeur resultset à la variable locale ou au paramètre de sortie dans la procédure?
Pour ci-dessous.
UPDATE TOP (1) certificatee WITH (ROWLOCK,READPAST,UPDLOCK) SET issued = 1 OUTPUT INSERTED.certid, INSERTED.certiname WHERE issued = 0 AND year = 2011
Vous pouvez définir une variable de table pour contenir la sortie:
DECLARE @OutputTable TABLE (CertID INT, CertiName VARCHAR(100)) -- adapt as needed UPDATE TOP (1) certificatee WITH (ROWLOCK,READPAST,UPDLOCK) SET issued = 1 OUTPUT INSERTED.certid, INSERTED.certiname INTO @OutputTable WHERE issued = 0 AND year = 2011 SELECT * FROM @OutputTable
et vous pouvez ensuite sélectionner à partir de cette variable de table pour returnner datatables de votre procédure stockée (ou juste pour y jeter un coup d'œil).
PS: le WITH (UPDLOCK)
est absolument superflu – n'importe quelle instruction UPDATE
prendra toujours un verrou de mise à jour de toute façon … vous pouvez simplement laisser cela de côté.
Puisque vous êtes en train de mettre à jour une seule ligne, essayez ceci:
DECLARE @certid INT DECLARE @certinname VARCHAR(MAX) -- or whatever UPDATE TOP (1) certificatee WITH (ROWLOCK,READPAST) SET issued = 1, @certid = certid, @certinname = certinname WHERE issued = 0 AND year = 2011 SELECT @certid, @certinname
DECLARE @certid INT DECLARE @certinname VARCHAR(MAX) -- or whatever UPDATE TOP (1) certificatee WITH (ROWLOCK,READPAST) SET issued = 1, @certid = certid, @certinname = certinname WHERE issued = 0 AND year = 2011 SELECT @certid, @certinname