USP_SMARTQUERYINSTANCERUNINFO_ADDORUPDATE
Parameters
Parameter | Parameter Type | Mode | Description |
---|---|---|---|
@ID | uniqueidentifier | IN | |
@LASTRUNDATE | date | IN | |
@LASTRUNDURATION | time | IN | |
@LASTRUNBY | uniqueidentifier | IN | |
@LASTRUNRESULTCOUNT | int | IN |
Definition
Copy
create procedure dbo.USP_SMARTQUERYINSTANCERUNINFO_ADDORUPDATE
(
@ID as uniqueidentifier,
@LASTRUNDATE as date,
@LASTRUNDURATION as time,
@LASTRUNBY as uniqueidentifier,
@LASTRUNRESULTCOUNT as int
)
as
begin
if exists (select 1 from dbo.SMARTQUERYINSTANCE where ID = @ID)
begin
merge SMARTQUERYINSTANCERUNINFO as target
using (select @ID as ID, @LASTRUNDATE as LASTRUNDATE, @LASTRUNDURATION as LASTRUNDURATION, @LASTRUNBY as LASTRUNBY, @LASTRUNRESULTCOUNT as LASTRUNRESULTCOUNT) as source
on target.ID = source.ID
when matched then
update set
target.LASTRUNDATE = source.LASTRUNDATE,
target.LASTRUNDURATION = source.LASTRUNDURATION,
target.LASTRUNBY = source.LASTRUNBY,
target.LASTRUNRESULTCOUNT = source.LASTRUNRESULTCOUNT,
target.RUNCOUNT = target.RUNCOUNT + 1
when not matched by target then
insert (
ID,
LASTRUNDATE,
LASTRUNDURATION,
LASTRUNBY,
LASTRUNRESULTCOUNT,
RUNCOUNT
)
values (
source.ID,
source.LASTRUNDATE,
source.LASTRUNDURATION,
source.LASTRUNBY,
source.LASTRUNRESULTCOUNT,
1
);
end
end