
[dbo].[BcImportDimensionValues]
create procedure [dbo].[BcImportDimensionValues]
@items BcDimensionValueImportItems readonly
as
begin
set nocount on
declare @now datetimeoffset = sysdatetimeoffset();
;with ImportData as
(
select
Items.BcId,
Items.LastModified,
Items.Code,
Items.[Description],
BcDimension.BcDimensionId
from @items Items
inner join BcDimension on Items.DimensionBcId = BcDimension.BcId
)
merge BcDimensionValue with (tablock) using ImportData on
BcDimensionValue.BcId = ImportData.BcId
when matched then update set
Code = ImportData.Code,
[Description] = ImportData.[Description],
LastImportedOn = @now,
LastUpdatedInBcOn = ImportData.LastModified
when not matched then insert
(
BcId,
BcDimensionFid,
Code,
[Description],
LastImportedOn,
CreatedOn,
LastUpdatedInBcOn
)
values
(
ImportData.BcId,
ImportData.BcDimensionId,
ImportData.Code,
ImportData.[Description],
@now,
@now,
ImportData.LastModified
)
;
end
GO
GRANT EXECUTE ON [dbo].[BcImportDimensionValues] TO [MssExec]
GO