如何在 Teradata 中将三个变量组合成日期 (MM/DD/YYYY)

发布于 2025-01-17 06:06:43 字数 367 浏览 4 评论 0原文

我在 Teradata 中有一个表,其中包含以下 3 列,以及创建可用于过滤表的日期的内容。

    Year Month Days
1   2,016   9   30
2   2,017   2   28
3   2,015   5   31

从以上 3 列创建日期后,“日期”表应如下所示。

    Year Month Days  Date
1   2,016   9   30  9/30/2016
2   2,017   2   28  2/28/2017
3   2,015   5   31  5/31/2015

我尝试过 TO_DATE、Cast 的不同变体等,但它出错了。

I have a table with the 3 below columns in Teradata and what to create a date that I can use to filter the table.

    Year Month Days
1   2,016   9   30
2   2,017   2   28
3   2,015   5   31

After the creation of a date from the 3 above columns, the 'date' table should look like so.

    Year Month Days  Date
1   2,016   9   30  9/30/2016
2   2,017   2   28  2/28/2017
3   2,015   5   31  5/31/2015

I have tried TO_DATE, different variations of Cast, etc. but it errors out.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

许仙没带伞 2025-01-24 06:06:43

假设现有列是 INT/SMALLINT/BYTEINT,您可以利用 Teradata 的“整数日期”表示形式:

CAST(("year"-1900)*10000 + "month"*100 + "days" AS DATE) as "date"

Assuming the existing columns are INT/SMALLINT/BYTEINT, you can leverage Teradata's "integerdate" representation:

CAST(("year"-1900)*10000 + "month"*100 + "days" AS DATE) as "date"
爱的十字路口 2025-01-24 06:06:43

您可以将结果视为字符串并连接所有列,只需更改年份 -

将来最好将日期和时间保存在适当的庄园中,因为您可以从中导出您拥有的所有列,并且需要更少的时间确定日期的时间

SELECT ('' || Days || '/' || Month  || '/' || CAST(oreplace(Year,',','') AS CHAR(4))  )

you can treat the result as string and concatenate all columns, only year has to be changed-

It would be better in future to save dats and times in a proper manor, as you can derive from it all columns you have, and it takes less time as to build a date

SELECT ('' || Days || '/' || Month  || '/' || CAST(oreplace(Year,',','') AS CHAR(4))  )
小巷里的女流氓 2025-01-24 06:06:43
select cast(cast(year*10000+Month*100+Day as char(10)) as date format'YYYYMMDD')
select cast(cast(year*10000+Month*100+Day as char(10)) as date format'YYYYMMDD')
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文