Home Return output from stored procedure
Reply: 0

Return output from stored procedure

user703
1#
user703 Published in April 25, 2018, 12:43 am

With the naked select I get the proper iden

declare @iden table (pk int);

update top (1) lockDate with (UPDLOCK) 
set dt = GETDATE()
output inserted.iden into @iden   
where dt is null 

select top (1) iden.pk
from @iden iden;

When I try and put it in a stored procedure I always get a 0.

Do you know what I am doing wrong?

DROP PROCEDURE addLockDate

CREATE PROCEDURE addLockDate
AS  
    DECLARE @iden TABLE (pk INT);

    UPDATE TOP (1) lockDate WITH (UPDLOCK) 
    SET dt = GETDATE()
    OUTPUT inserted.iden INTO @iden   
    WHERE dt IS NULL

    RETURN SELECT TOP (1) iden.pk
           FROM @iden iden
GO
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.311663 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO