为 SSIS 包目的在 SQL 服务器中投射列

Casting columns in SQL Server for SSIS package purpose

我坚持在 SQL 服务器中投射数据。我正在做一个 SSIS 包来将数据从 SQL 服务器传输到 Oracle 数据库,在 Oracle 中,我有这些类型的列:

Registered_hours: number(3,1)
Approved_hours: number(4,2)

代表整小时和半小时。我的意思是例如:3.5h

在我的 SQL 服务器数据库中,我有这些列,但我存储的是分钟而不是小时。所以我有 ex 的值:480(8 小时)。

Registered_hours: int
Approved_hours: int

如何正确cast/convert这个值?例如:在 SQL 服务器中,我有 510 分钟,相当于 8.5 小时。我需要在转换后得到这个值。

您可以使用 Derived Column Transformation 添加派生列,表达式如下 (小时 = 分钟 / 60)

我使用 (DT_NUMERIC,10,0) 因为 Registered_hours / 60 return 没有它的整数值

(DT_NUMERIC,3,1)((DT_NUMERIC,10,0)Registered_hours / 60)

(DT_NUMERIC,4,2)((DT_NUMERIC,10,0)Approved_hours/ 60)

参考资料

据我了解,您想将(例如)510 转换为 8.5。如果是这样,这样做有什么好处吗?

您只需要最后一个 converted 值,但我选择了一步一步来,以便您了解我为什么以及如何做到这一点。

SQL> with test as (select 65 minutes from dual union
  2                select 480        from dual union
  3                select 510        from dual)
  4  select minutes,
  5    trunc(minutes / 60) hours,
  6    round((minutes - (trunc(minutes / 60) * 60)) / 60, 2) hours_add,
  7    --
  8    trunc(minutes / 60) +
  9    round((minutes - (trunc(minutes / 60) * 60)) / 60, 2) converted
 10  from test;

   MINUTES      HOURS  HOURS_ADD  CONVERTED
---------- ---------- ---------- ----------
        65          1        ,08       1,08
       480          8          0          8
       510          8         ,5        8,5

SQL>