sql - SELECT 1 FROM [SystemEventLog] -


i using sql server 2008 r2.

i have sql job executes stored procedure daily 8:00 am.

in stored, there statement :

    declare @midnight datetime,     @starttime datetime = getutcdate();      -- has stored procedure run today?     if exists (select 1 [systemeventlog] [createddatetime_utc] >= cast(@midnight date) , [createddatetime_utc] < dateadd(dd, 1, cast(@midnight date)))     begin          return     end   -- log storedproc ran declare @systemeventlogid int  insert [dbo].[systemeventlog] ( [eventtype_id], [storedprocname], [details] ) values( 1, 'storedprocedureone', null ) 

according comment, block checking whether store procedure has run today or not, if yes return.

but not getting how checks whether procedure has alreday ran today or not?

can explain?

thanks.

breaking stored procedure down ...

select 1 [systemeventlog]     [createddatetime_utc] >= cast(@midnight date)       , [createddatetime_utc] < dateadd(dd, 1, cast(@midnight date)) 

this output single row (the 1 irrelevant - it's content) if condition met.

then ...

if exists ( [statement] )  

is true if [statement] returns @ least 1 row. if true, stored procedure exits (through return statement); if false, continue.

the part missing example below this, add new line systemeventlog - on later executions - make condition true rest of day.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -