Back to OIM Explorer

dbo.QBM_FGISessionErrorForLog_i

Scalar FunctionSQL_SCALAR_FUNCTIONSandbox DB

Scalar Function.

Source: sandbox-db sys.sql_modules

Source size: 2.126 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_FGISessionErrorForLog source text reference
  • references source dbo.QBM_FTSessionErrorLoad source text reference

Complete Source

SQL118 lines
1CREATE FUNCTION dbo.QBM_FGISessionErrorForLog_i(2  @RowDelimiter nvarchar(16)3) RETURNS nvarchar(max4)5AS6BEGIN7  DECLARE @erg nvarchar(max) = N ''8  DECLARE @Start nvarchar(max) = N ''9  DECLARE @ExistingErrors QBM_YSessionError10  DECLARE @ElementCount int11  DECLARE @ElementIndex int12  DECLARE @IsRethrow BIT13  INSERT INTO @ExistingErrors(ErrorMessage,14  ErrorSeverity,15  ErrorState,16  ErrorNumber,17  ProcedureName,18  ProcedureLine,19  MessageDate,20  GenProcID,21  RepeatCounter,22  IsReThrow,23  SourceCode)24  SELECT25    ErrorMessage,26    ErrorSeverity,27    ErrorState,28    ErrorNumber,29    ProcedureName,30    ProcedureLine,31    MessageDate,32    GenProcID,33    RepeatCounter,34    IsReThrow,35    SourceCode36  FROM dbo.QBM_FTSessionErrorLoad() el37  ORDER BY el.RecordNumber DESC38  SELECT @ElementCount = @@ROWCOUNT39  SELECT @ElementIndex = 140  WHILE @ElementIndex <= @ElementCount41  BEGIN42    IF @erg > N ' '43    BEGIN44      SELECT45        @erg = CONCAT(@erg,46        @RowDelimiter)47    END48    SELECT49      @erg = CONCAT(@Start,50      @erg,51      TRIM(str(e.ErrorNumber)),52      NCHAR(9),53      TRIM(str(CASE e.ErrorState54      WHEN 1 THEN55      056      WHEN 2 THEN57      158      WHEN 3 THEN59      260    ELSE 061    END)),62    NCHAR(9),63    CASE e.IsReThrow64      WHEN 0 THEN65    e.ErrorMessage66      WHEN 1 THEN67    CONCAT(N 're-throw in ', e.ProcedureName, ' Line ', trim(str(ISNULL(e.ProcedureLine, 0))))68    END),69    @IsRethrow = e.IsReThrow70    FROM @ExistingErrors e71    WHERE72      e.ElementIndex = @ElementIndex73    IF @IsRethrow = 074    BEGIN75      IF @erg > N ' '76      BEGIN77        SELECT78          @erg = CONCAT(@erg,79          @RowDelimiter)80      END81      SELECT82        @erg = CONCAT(@Start,83        @erg,84        TRIM(str(e.ErrorNumber)),85        NCHAR(9),86        TRIM(str(CASE e.ErrorState87        WHEN 1 THEN88        089        WHEN 2 THEN90        191        WHEN 3 THEN92        293      ELSE 094      END)),95      NCHAR(9),96      CONCAT('detected in ', ' (SRV=', @@servername, ', DB=',97      LEFT(DB_Name(), 64), N ') ', 'procedure ', e.ProcedureName, ' Line ', trim(str(ISNULL(e.ProcedureLine,98      0)))),99      CASE100        WHEN e.RepeatCounter > 0 THEN101      ' repeated ' + TRIM(str(e.RepeatCounter)) + ' times '102      ELSE ''103      END,104      CASE105        WHEN e.SourceCode > ' ' AND e.SourceCode NOT LIKE '<no code>%' THEN106      ' code starting with : ' +107      LEFT(e.SourceCode, 6000)108      ELSE ''109      END)110      FROM @ExistingErrors e111      WHERE112        e.ElementIndex = @ElementIndex113    END114    SELECT @ElementIndex += 1115  END116  endLabel:117  RETURN(@erg)118END
Open raw exported source
SQL ยท Raw15 lines
1 create   function dbo.QBM_FGISessionErrorForLog_i( @RowDelimiter nvarchar(16) ) returns nvarchar(max) as begin declare @erg nvarchar(max) = N''2 declare @Start nvarchar(max) = N'' declare @ExistingErrors QBM_YSessionError declare @ElementCount int declare @ElementIndex int declare @IsRethrow bit3 insert into @ExistingErrors (ErrorMessage, ErrorSeverity, ErrorState, ErrorNumber , ProcedureName, ProcedureLine, MessageDate , GenProcID, RepeatCounter4, IsReThrow, SourceCode) select ErrorMessage, ErrorSeverity, ErrorState, ErrorNumber , ProcedureName, ProcedureLine, MessageDate , GenProcID, RepeatCounter5, IsReThrow, SourceCode from dbo.QBM_FTSessionErrorLoad() el order by el.RecordNumber desc select @ElementCount = @@ROWCOUNT select @ElementIndex = 1 while6 @ElementIndex <= @ElementCount begin if @erg > N' ' begin select @erg = concat(@erg, @RowDelimiter) end select @erg = concat (@Start  , @erg  , TRIM(str7(e.ErrorNumber)) , NCHAR(9) , TRIM(str( case e.ErrorState  when 1 then 0 when 2 then 1 when 3 then 2 else 0  end )) , NCHAR(9) ,  case e.IsReThrow when8 0 then e.ErrorMessage when 1 then concat( N're-throw in ', e.ProcedureName, ' Line ', trim(str(ISNULL(e.ProcedureLine, 0))) ) end  )  , @IsRethrow = e.IsReThrow9 from @ExistingErrors e where e.ElementIndex = @ElementIndex if @IsRethrow = 0  begin if @erg > N' ' begin select @erg = concat(@erg, @RowDelimiter) end10 select @erg = concat (@Start  , @erg  , TRIM(str(e.ErrorNumber)) , NCHAR(9) , TRIM(str( case e.ErrorState  when 1 then 0 when 2 then 1 when 3 then 2 else11 0  end )) , NCHAR(9)  , concat( 'detected in ' , ' (SRV=' , @@servername  , ', DB=' , left(DB_Name(), 64) , N') ' , 'procedure ' , e.ProcedureName, ' Line '12, trim(str(ISNULL(e.ProcedureLine, 0))) ) , case when e.RepeatCounter > 0 then ' repeated ' + TRIM(str(e.RepeatCounter)) + ' times ' else '' end , case13 when e.SourceCode > ' ' and e.SourceCode not like '<no code>%' then ' code starting with : ' + left(e.SourceCode, 6000) else '' end  )  from @ExistingErrors14 e where e.ElementIndex = @ElementIndex end  select @ElementIndex += 1 end  endLabel: return(@erg) end 15