ETL 日期时间到整数错误代码

ETL datetime to integer error code

我在 visual studio 2017 年写了一个 ETL,我收到了这个错误:

所以,我无法将日期时间数据类型转换为整数数据类型。

但问题是,我的查询 return 是一个 int 而不是 datetime 数据类型。 查询:

SELECT    e.eventName, e.eventType, e.numberOfPersons, 
          (SELECT timeKey FROM StarSchema.dbo.timeDim WHERE (r.reservationDate = [DATE])) AS reservationDate,
          (SELECT timeKey FROM StarSchema.dbo.timeDim AS timeDim_2 WHERE (e.eventStartDate = [DATE])) AS eventStartDate,
          (SELECT timeKey FROM StarSchema.dbo.timeDim AS timeDim_1 WHERE (e.eventEndDate = [DATE])) AS eventEndDate,
          contact.name, customer.company, invoices.price, invoices.invoiceId
FROM      events AS e 
          INNER JOIN reservation AS r ON e.reservationId = r.reservationId 
          INNER JOIN customer ON e.customerId = customer.customerId 
          INNER JOIN contact ON customer.contactId = contact.contactId 
          INNER JOIN invoices ON e.invoiceId = invoices.invoiceId

这是我 运行 这个查询时的结果: reservationDate、eventStartDate 和 eventEndDate 在我的时间维度中引用了一个键,作为 int 而不是日期时间。

我尝试使用此查询创建一个视图,然后在我的 ETL 中使用它,但 Visual studio 仍然将这些列作为日期时间数据类型处理。

有什么建议吗?

**编辑:明确地说,我的目标是将数据类型 return 作为 INT 而不是日期数据类型。我需要 INT 来参考我的时间维度。

尝试在内部使用 CAST 作为 DATE:

SELECT    e.eventName, e.eventType, e.numberOfPersons, 
          (SELECT CAST (timeKey AS DATE) FROM ArenAStar.dbo.timeDim WHERE 
          (r.reservationDate = [DATE])) AS reservationDate,
      (SELECT CAST (timeKey AS DATE) FROM ArenAStar.dbo.timeDim AS timeDim_2 
WHERE 
      (e.eventStartDate = [DATE])) AS eventStartDate,
      (SELECT timeKey FROM ArenAStar.dbo.timeDim AS timeDim_1 WHERE 
      (e.eventEndDate = [DATE])) AS eventEndDate,
      contact.name, customer.company, invoices.price, invoices.invoiceId
FROM  events AS e 
      INNER JOIN reservation AS r ON e.reservationId = r.reservationId 
      INNER JOIN customer ON e.customerId = customer.customerId 
      INNER JOIN contact ON customer.contactId = contact.contactId 
      INNER JOIN invoices ON e.invoiceId = invoices.invoiceId