ETL datetime到整数错误代码

时间:2018-01-16 15:51:27

标签: sql sql-server visual-studio etl sqldatatypes

我在Visual Studio 2017中编写了一个ETL,我收到了这个错误: Error Message

因此,我无法将datetime数据类型转换为整数数据类型。

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

>>> x = 1
>>> type(x)
<type 'int'>
>>> x = "sss"
>>> type(x)
<type 'str'>

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

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

有什么建议吗?

**编辑:所以要清楚,我的目标是让数据类型返回INT而不是日期数据类型。我需要INT来引用我的时间维度。

1 个答案:

答案 0 :(得分:0)

在内部使用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