在 SSIS 中调用标量值函数
有什么方法可以从 SSIS 中的派生列转换中执行标量值函数吗?
-场景-
我的源数据库中有一个函数,可以根据记录的 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
Is there any way to execute a scalar-valued function from within a Derived Column transformation in SSIS?
-Scenario-
I have a function in my source DB that converts weights based on a UOM value in the record's UOM column. I want to utilize this function in the ETL process to ensure that my weight measures are always pounds. Can I call this function from within a Derived Column? If not, is there another transformation task I could utilize within the Data Flow (trying to avoid staging columns)?
dbo.Tasks table
id | Name | netWeight | grossWeight | UOM
12 Task12 30000 50000 10
dbo.MeasurementUnits table
id | Name | Shortname | Type | Precision
12 Kilogram kg 3 10000
14 Pound lb 3 10000
dbo.GetConvertedWeight function
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
Example function call
dbo.GetConvertedWeight(dbo.Tasks.netWeight, dbo.Tasks.weightUOM, 14) AS netWeight
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
没有。 您需要的是 OLE DB 命令 来执行此操作。 将结果发送到输出列,您的生活应该会很美好——至少对于 SSIS 来说是这样。
Nope. What you'll want is an OLE DB Command to do that. Send the results to an Output Column, and life should be peachy keen for you--at least with regards to SSIS.