Back to OIM Explorer

dbo.QBM_FSQTriggerWatchSemaphor

Scalar FunctionSQL_SCALAR_FUNCTIONSandbox DB

Scalar Function. References QBM_PDBQueueInsert_Single

Source: sandbox-db sys.sql_modules

Source size: 2.703 characters

Interpretation

  • Database function. Usually supports views, validation, or calculated predicates; look at referenced-by entries for callers.
  • DBQueue relation detected. Follow the task procedure and referenced-by list for async processing.

Relations

  • References QBM_PDBQueueInsert_Single

Typed Edges

  • references source dbo.QBM_PDBQueueInsert_Single source text reference

Complete Source

SQL104 lines
1CREATE FUNCTION dbo.QBM_FSQTriggerWatchSemaphor(2  @TableName nvarchar(64),3  @operation nvarchar(16)4) RETURNS nvarchar(max5)6AS7BEGIN8  DECLARE @erg nvarchar(max) = ''9  DECLARE @medium nvarchar(max)10  DECLARE @pattern nvarchar(max) = '			if @IsSemaphorInFullsync = 111				 begin12					if not exists 13						(select top 1 114							from DialogDBQueue q with (readpast)15							where q.UID_Task = ''QBM-K-CommonIncSemaphorPost''16							 and q.Object = ''@Semaphorname@''17							 and q.Generation >= 018						)19					begin20						exec QBM_PDBQueueInsert_Single ''QBM-K-CommonIncSemaphorPost'', ''@Semaphorname@'', null, @GenProcID21					end22				 end23				else24				 begin25					if not exists 26						(select top 1 127							from DialogDBQueue q with (readpast)28							where q.UID_Task = ''QBM-K-CommonIncSemaphor''29						 and q.Object = ''@Semaphorname@''30							 and q.Generation >= 031						)32					begin33						exec QBM_PDBQueueInsert_Single ''QBM-K-CommonIncSemaphor'', ''@Semaphorname@'', null, @GenProcID34					end35				 end'36  + nchar(13) + nchar(10)37  SELECT38    @medium = string_agg(convert(nvarchar(max), CONCAT(CASE @operation39    WHEN 'update' THEN40    CONCAT('	 if update(', z.columnname, ')', nchar(13), nchar(10), '	  begin', nchar(13), nchar(10))41  ELSE ''42  END, z.zeile, CASE @operation43  WHEN 'update' THEN44  CONCAT('	  end -- 	 if update(', z.columnname, ')', nchar(13), nchar(10))45  ELSE ''46  END)),47  nchar(13) + nchar(10))48  FROM(49  SELECT50    y.columnname,51    string_agg(replace(@pattern, '@Semaphorname@', y.SemaphorName), nchar(13) + nchar(10)) within52    GROUP(53  ORDER BY y.SemaphorName) AS zeile54  FROM(55  SELECT56    DISTINCT CASE @operation57    WHEN 'update' THEN58    a.columnname59  ELSE ''60  END AS columnname, a.Semaphorname61  FROM(62  SELECT63    DISTINCT c.ColumnName, se.ChangeContext AS SemaphorName64  FROM dbo.DialogTable t65    WITH(readpast)66  JOIN dbo.DialogColumn c67    WITH(readpast)68    ON t.UID_DialogTable = c.UID_DialogTable AND t.TableName = @TableName69  JOIN dbo.DialogColumnHasSemaphor ch70    WITH(readpast)71    ON c.UID_DialogColumn = ch.UID_DialogColumn72  JOIN dbo.DialogSemaphor se73    WITH(readpast)74    ON ch.UID_DialogSemaphor = se.UID_DialogSemaphor75  WHERE76    (c.IsPKMember = 1 AND @Operation = 'insert' OR c.IsPKMember = 0 AND @Operation = 'update' OR c.IsPKMember = 1 AND @Operation = 'delete')) AS77  a) AS y78  GROUP BY y.columnname) AS z79  IF @medium > ' '80  BEGIN81    SELECT82      @erg = CONCAT(replicate(N '-', 64),83      nchar(13),84      nchar(10),85      N '-- SemaphorCheck',86      nchar(13),87      nchar(10),88      replicate(N '-', 64),89      nchar(13),90      nchar(10),91      @medium,92      replicate(N '-', 64),93      nchar(13),94      nchar(10),95      N '-- / SemaphorCheck',96      nchar(13),97      nchar(10),98      replicate(N '-', 64),99      nchar(13),100      nchar(10))101  END102  ende:103  RETURN(@erg)104END
Open raw exported source
SQL ยท Raw39 lines
1     create   function dbo.QBM_FSQTriggerWatchSemaphor (@TableName nvarchar(64), @operation nvarchar(16) ) returns nvarchar(max)    as begin declare2 @erg nvarchar(max) = '' declare @medium nvarchar(max) declare @pattern nvarchar(max) = '			if @IsSemaphorInFullsync = 13				 begin4					if not exists 5						(select top 1 16							from DialogDBQueue q with (readpast)7							where q.UID_Task = ''QBM-K-CommonIncSemaphorPost''8							 and q.Object = ''@Semaphorname@''9							 and q.Generation >= 010						)11					begin12						exec QBM_PDBQueueInsert_Single ''QBM-K-CommonIncSemaphorPost'', ''@Semaphorname@'', null, @GenProcID13					end14				 end15				else16				 begin17					if not exists 18						(select top 1 119							from DialogDBQueue q with (readpast)20							where q.UID_Task = ''QBM-K-CommonIncSemaphor''21						 and q.Object = ''@Semaphorname@''22							 and q.Generation >= 023						)24					begin25						exec QBM_PDBQueueInsert_Single ''QBM-K-CommonIncSemaphor'', ''@Semaphorname@'', null, @GenProcID26					end27				 end'28 + nchar(13) + nchar(10) select @medium = string_agg(convert(nvarchar(max), concat( case @operation when 'update' then concat('	 if update(' , z.columnname29 , ')' , nchar(13) , nchar(10), '	  begin' , nchar(13) , nchar(10) ) else '' end , z.zeile , case @operation when 'update' then concat('	  end -- 	 if update('30 , z.columnname , ')' , nchar(13) , nchar(10) ) else '' end )  )  , nchar(13) + nchar(10) )  from ( select y.columnname, string_agg( replace(@pattern, 31'@Semaphorname@', y.SemaphorName) , nchar(13) + nchar(10) ) within group (order by y.SemaphorName) as zeile from ( select distinct case @operation when32 'update' then a.columnname else '' end as columnname, a.Semaphorname from ( select distinct c.ColumnName, se.ChangeContext as SemaphorName from dbo.DialogTable33 t with (readpast) join dbo.DialogColumn c with (readpast) on t.UID_DialogTable = c.UID_DialogTable and t.TableName = @TableName join dbo.DialogColumnHasSemaphor34 ch with (readpast) on c.UID_DialogColumn = ch.UID_DialogColumn join dbo.DialogSemaphor se with (readpast) on ch.UID_DialogSemaphor = se.UID_DialogSemaphor35 where ( c.IsPKMember = 1 and @Operation = 'insert' or c.IsPKMember = 0 and @Operation = 'update' or c.IsPKMember = 1 and @Operation = 'delete' ) ) as 36a ) as y group by y.columnname ) as z if @medium > ' ' begin select @erg = concat(replicate(N'-', 64) , nchar(13) , nchar(10) , N'-- SemaphorCheck' , nchar37(13) , nchar(10) , replicate(N'-', 64) , nchar(13) , nchar(10) , @medium , replicate(N'-', 64) , nchar(13) , nchar(10) , N'-- / SemaphorCheck' , nchar(1338) , nchar(10) , replicate(N'-', 64) , nchar(13) , nchar(10) ) end  ende: return(@erg) end 39