IF(exists (select 1 from dbo.T_ENTITY_IDS where EntName = 'RDS.EXPORT_FRLLO_NEEDS_ELEMENT' and FieldName = 'PrimaryKey'))
BEGIN
	update dbo.T_ENTITY_IDS set id = Coalesce((select max(ExportFrlloNeedsElementID) + 1 from RDS.T_EXPORT_FRLLO_NEEDS_ELEMENT), 0) where EntName = 'RDS.EXPORT_FRLLO_NEEDS_ELEMENT' and FieldName = 'PrimaryKey';
END
ELSE
BEGIN

	INSERT INTO [dbo].[T_ENTITY_IDS]
           ([EntName]
           ,[FieldName]
           ,[id])
     VALUES
           ('RDS.EXPORT_FRLLO_NEEDS_ELEMENT'
           ,'PrimaryKey'
           ,Coalesce((select max(ExportFrlloNeedsElementID) + 1 from RDS.T_EXPORT_FRLLO_NEEDS_ELEMENT), 0))
END

IF(exists (select 1 from dbo.T_ENTITY_IDS where EntName = 'RDS.EXPORT_FRLLO_NEEDS_EQUIP' and FieldName = 'PrimaryKey'))
BEGIN
	update dbo.T_ENTITY_IDS set id = Coalesce((select max(ExportFrlloNeedsEquipID) + 1 from RDS.T_EXPORT_FRLLO_NEEDS_EQUIP), 0) where EntName = 'RDS.EXPORT_FRLLO_NEEDS_EQUIP' and FieldName = 'PrimaryKey';
END
ELSE
BEGIN

	INSERT INTO [dbo].[T_ENTITY_IDS]
           ([EntName]
           ,[FieldName]
           ,[id])
     VALUES
           ('RDS.EXPORT_FRLLO_NEEDS_EQUIP'
           ,'PrimaryKey'
           ,Coalesce((select max(ExportFrlloNeedsEquipID) + 1 from RDS.T_EXPORT_FRLLO_NEEDS_EQUIP), 0))
END


