Back to OIM Explorer

dbo.QBM_FGIDBServerIsActive

Scalar FunctionSQL_SCALAR_FUNCTIONSandbox DB

Scalar Function.

Source: sandbox-db sys.sql_modules

Source size: 837 characters

Interpretation

  • Database function. Usually supports views, validation, or calculated predicates; look at referenced-by entries for callers.

Relations

  • No extracted relations.

Typed Edges

  • references source dbo.QBM_FGIDate source text reference
  • references source dbo.QBM_FGIDBServerCurrStatement source text reference

Complete Source

SQL51 lines
1CREATE FUNCTION dbo.QBM_FGIDBServerIsActive(2  @spid int,3  @CountSeconds int4) RETURNS int5AS6BEGIN7  DECLARE @Erg int = -18  DECLARE @LastRead datetime = NULL9  DECLARE @dbid int = -110  IF @spid < 111  BEGIN12    RETURN(@erg)13  END14  SELECT TOP 1 @dbid = p.dbid15  FROM sys.sysprocesses p16  WHERE17    p.spid = @spid18  IF @dbid = -119  BEGIN20    RETURN(@erg)21  END22  IF @dbid <>db_id()23  BEGIN24    SELECT @Erg = -225    RETURN(@erg)26  END27  SELECT TOP 1 @LastRead = c.last_write28  FROM sys.dm_exec_connections c29  WHERE30    (c.session_id = @spid OR c.most_recent_session_id = @spid)31  IF isnull(@LastRead,32  '1899-12-30') > '1899-12-30'33  BEGIN34    SELECT @Erg = 035  END36  IF DATEADD(ss,37  @CountSeconds,38  @LastRead) > dbo.QBM_FGIDate()39  BEGIN40    SELECT @Erg = 141  END42  ELSE43  BEGIN44    IF dbo.QBM_FGIDBServerCurrStatement(@spid) LIKE '%waitfor%'45    BEGIN46      SELECT @Erg = 247    END48  END49  endLabel:50  RETURN(@erg)51END
Open raw exported source
SQL ยท Raw7 lines
1   create   function dbo.QBM_FGIDBServerIsActive(@spid int  , @CountSeconds int  ) returns int as begin declare @Erg int = -1 declare @LastRead 2datetime = null declare @dbid int = -1 if @spid < 1 begin  return(@erg)  end select top 1 @dbid = p.dbid from sys.sysprocesses p where p.spid = @spid if3 @dbid = -1  begin   return(@erg)  end if @dbid <>db_id() begin select @Erg = -2  return(@erg)  end select top 1 @LastRead = c.last_write from sys.dm_exec_connections4 c where ( c.session_id = @spid or c.most_recent_session_id = @spid ) if isnull(@LastRead , '1899-12-30') > '1899-12-30' begin select @Erg = 0 end if DATEADD5(ss, @CountSeconds, @LastRead) > dbo.QBM_FGIDate()  begin select @Erg = 1 end else begin if dbo.QBM_FGIDBServerCurrStatement(@spid) like '%waitfor%' begin6 select @Erg = 2 end end endLabel: return(@erg) end 7