How to create a select, and then an update stored procedure in SQL Server 2012 -


i'm trying create stored procedure runs select query , pulls id (variable) , update query id. appreciated.

this have:

create procedure dbo.lead_usp_getlead     @leadid int output     select top 1          leadid, leadinitials, leadfirstname, leadsurname,         leadhometelephonenumber, leadworktelephonenumber,        leadcellularnumber, leademailaddress, islocked, uploadeddate            dbo.lead            islocked = 'false'    order         uploadeddate;     update dbo.lead    set islocked = 'true'    leadid = @leadid     declare @leadid int     exec dbo.lead_usp_getlead @leadid; 

you can combine them. no need 2 queries:

with toupdate (       select top 1 l.*       dbo.lead l       l.islocked = 'false'       order l.uploadeddate      ) update toupdate     set islocked = 'true'; 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -