在加入SQL时如何将日期时间转换为日期数据类型?

发布于 2025-01-15 05:46:35 字数 858 浏览 0 评论 0原文

我试图将两个数据集连接在一起,同时更改输出中出现的数据类型。

当我运行以下命令时,联接进程,但我尚未将日期时间列转换为日期列:


SELECT  *
FROM [DATABASE].[table1]
     LEFT JOIN [DATABASE].[View] ON DATABASE.Column6=View.Column7

下面是我尝试使用 CAST() 修复我的日期列 当我运行这个程序时,试图通过明确地解决我的日期时间问题,联接不起作用:

SELECT [Table1].[Column1] as 'c1',
       [Table1].[Column2] as 'c2',
       [Table1].[Column3] as 'c3',
       [Table1].[Column4] as 'c4',
       [Table1].[Column5] as 'c5',
       [Table1].[Column6] as 'c6',
       CAST([Table1].[Start_Date] AS Date) AS 'Start_Date',
       CAST([Table1].[End_Date] AS Date) AS 'End_Date',
       [Table1].[Column7] as 'c7',
       [Table1].[Column8] as 'c8',
       [Table1].[Column9] as 'c9'
FROM [DATABASE].[Table1]
      LEFT JOIN [DATABASE].[View] ON Table1.Column6=View.Column7

有人明白为什么会这样吗?我希望得到解释。

I am trying to join two datasets together while changing a datatype that will appear in the output.

When I run the following, the join processes, but I have not converted my datetime columns to date columns:


SELECT  *
FROM [DATABASE].[table1]
     LEFT JOIN [DATABASE].[View] ON DATABASE.Column6=View.Column7

Below is my attempt to fix my date columns with CAST()
When I run this, trying to fix my datetime issue, by being explicit, the join does not work:

SELECT [Table1].[Column1] as 'c1',
       [Table1].[Column2] as 'c2',
       [Table1].[Column3] as 'c3',
       [Table1].[Column4] as 'c4',
       [Table1].[Column5] as 'c5',
       [Table1].[Column6] as 'c6',
       CAST([Table1].[Start_Date] AS Date) AS 'Start_Date',
       CAST([Table1].[End_Date] AS Date) AS 'End_Date',
       [Table1].[Column7] as 'c7',
       [Table1].[Column8] as 'c8',
       [Table1].[Column9] as 'c9'
FROM [DATABASE].[Table1]
      LEFT JOIN [DATABASE].[View] ON Table1.Column6=View.Column7

Does anyone understand why this would be? I would appreciate an explanation.

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文