
/****** Object:  UserDefinedFunction [dbo].[ApiGetTSSec]    Script Date: 07.09.2021 06:14:52 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE FUNCTION [dbo].[ApiGetTSSec]
(
	@SourceTable [varchar](16), 
	@GUID [uniqueidentifier]
	
)
RETURNS  int
BEGIN
   DECLARE @res int;
 set @res = ISNULL((
	select top 1 
	CAST(DATEDIFF(second, '1970-01-01', 
	--CAST(GetUtcDate() AS date)
	 --DATEADD(HOUR,DATEDIFF(hour, CURRENT_TIMESTAMP,GetUtcDate()),Time)
	 Time
	) AS bigint) 
	--,*
	 from dbo.ChangeInfos where SourceGuid = @GUID and SourceTable = @SourceTable ORDER BY Time DESC),0);
	 return @res;
END




