求用一句话完成本procedure的全部功能
现有procedure如下:
CREATE PROCEDURE updateLastReqEvent
@p_adminkey int
as
declare @tmpvar int
BEGIN
set @tmpvar = 0
While c_requestnum IN (SELECT distinct rm.requestnumber
FROM metarequestactivitytemp rat,
metarequestmap rm,
metarequeststatusimagemap rsi
WHERE rat.islast = 'Y '
AND rat.requestid = rm.requestid
AND rat.requeststatus = rsi.requests)
begin
UPDATE requestevent
SET islast = 'N '
WHERE requestnumber = c_requestnum.requestnumber AND islast = 'Y ';
END
END
如何用一句话高效率的完成本procedure???
------解决方案--------------------可以用一條語句實現
UPDATE
req
SET islast = 'N '
From
requestevent req, metarequestactivitytemp rat, metarequestmap rm, metarequeststatusimagemap rsi
WHERE rat.requestid = rm.requestid AND rat.requeststatus = rsi.requests AND rm.requestnumber = req.requestnumber
AND req.islast = 'Y ' AND rat.islast = 'Y '