在加入SQL时如何将日期时间转换为日期数据类型?
我试图将两个数据集连接在一起,同时更改输出中出现的数据类型。
当我运行以下命令时,联接进程,但我尚未将日期时间列转换为日期列:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论