
/****** Object:  View [dbo].[ApiObjectRelationsView]    Script Date: 13.09.2021 14:59:03 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE VIEW [dbo].[ApiObjectRelationsView] as
SELECT  [Id],[ObjectType],[ObjectId],[Description],[TS],[RelObjectId],[RelObjectType],[OperatorId]
      ,[Value],[HistoryParentId]
  FROM [dbo].[ApiObjectRelations]
  UNION
  select d.ID Id,1 [ObjectType], t.Id, 'Enova'  [Description], CURRENT_TIMESTAMP TS, Dokument [RelObjectId], 10 [RelObjectType],
  0 [OperatorId], cast ( 0 as decimal) [Value], 0 [HistoryParentId]
   from 
  dbo.DokumentyCRM  d  JOIN dbo.ApiCrmTasks t ON t.ErpId = Zadanie and DokumentType='DokHandlowe'
GO


