有没有办法在SSIS中的派生列转换中执行标量值函数?
-Scenario -
我的源数据库中有一个函数,它根据记录的UOM列中的UOM值转换权重。我想在ETL过程中使用这个功能,以确保我的体重测量总是磅。我可以在派生列中调用此函数吗?如果没有,我是否可以在数据流中使用另一个转换任务(试图避免分段列)?
dbo.Tasks表
id | Name | netWeight | grossWeight | UOM
12 Task12 30000 50000 10
dbo.MeasurementUnits表
id | Name | Shortname | Type | Precision
12 Kilogram kg 3 10000
14 Pound lb 3 10000
dbo.GetConvertedWeight函数
ALTER FUNCTION [dbo].[GetConvertedWeight](@iWeight money, @ifromUOM int, @iToUOM int)
RETURNS money
AS
BEGIN
DECLARE @lConvertedWeight money,
@lKgToGrams money,
@lLbToGrams money,
@lOzToGrams money,
@lWeightInGrams money
--convert the weight to grams first.
SELECT @lWeightInGrams = CASE WHEN @iFromUOM = 12 THEN (ISNULL(@iWeight,0) * 1000)
WHEN @iFromUOM = 14 THEN (ISNULL(@iWeight,0) * 453.5924)
WHEN @iFromUOM = 15 THEN (ISNULL(@iWeight,0) * 28.3495)
WHEN @iFromUOM = 13 THEN (ISNULL(@iWeight,0))
ELSE ISNULL(@iWeight,0)
END
--Convert the converted weight to grams to the desired weight
SELECT @lConvertedWeight = CASE WHEN @iToUOM = 12 THEN (ISNULL(@lWeightInGrams,0) / 1000)
WHEN @iToUOM = 13 THEN ISNULL(@lWeightInGrams,0)
WHEN @iToUOM = 14 THEN (ISNULL(@lWeightInGrams,0)/453.5924)
WHEN @iToUOM = 15 THEN (ISNULL(@lWeightInGrams,0) / 28.3495 )
ELSE (ISNULL(@lWeightInGrams,0)/453.5924)
END
RETURN @lConvertedWeight
示例函数调用
dbo.GetConvertedWeight(dbo.Tasks.netWeight, dbo.Tasks.weightUOM, 14) AS netWeight