Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 如何使用ON子句从日期时间列中选择日期和时间_Sql_Sql Server_Sql Server 2008_Sql Server 2005 - Fatal编程技术网

Sql 如何使用ON子句从日期时间列中选择日期和时间

Sql 如何使用ON子句从日期时间列中选择日期和时间,sql,sql-server,sql-server-2008,sql-server-2005,Sql,Sql Server,Sql Server 2008,Sql Server 2005,我有一个连接查询 SELECT vs.Id as 'VitalId', ms.PatientId as 'PatientId', ms.CustomerId as 'CustomerId', ms.CreatedUtc from A1 a join B1 b on a.CreatedUtc = b.concat(concat(convert(date,S.CreatedUtc),':'), datepart(hour,S

我有一个连接查询

SELECT  vs.Id as 'VitalId', ms.PatientId as 'PatientId',  ms.CustomerId  as 'CustomerId', ms.CreatedUtc
from A1 a
join B1 b
    on a.CreatedUtc = b.concat(concat(convert(date,S.CreatedUtc),':'),
                               datepart(hour,S.CreatedUtc))
实际上,我想将a.CreatedUtc映射到日期和时间到b表(即:-B2)。 这个查询有用吗。?因为当我运行此查询时,不会插入任何记录

有谁能告诉我如何使用ON子句从Datetime列中只获取日期和时间吗?

这就是您想要的吗

select vs.Id as VitalId, ms.PatientId as PatientId,  
       ms.CustomerId  as CustomerId, ms.CreatedUtc
from A1 a join
     B1 b
     on convert(date, a.CreatedUtc) = convert(date, S.CreatedUtc) and
        datepart(hour, a.CreatedUtc) = datepart(hour, S.CreatedUtc);

请显示两个表的示例数据和表结构。无论模式和实际问题是什么,都没有理由对日期使用字符串操作。如果任何
CreatedUtc
是文本,那么真正的问题是错误的数据类型,而不是连接表达式。在这两种情况下,都不可能在这些字段上使用索引,从而使查询非常缓慢,而不是准确地进行。。我不想约会。。是否可以在单行中实现日期和小时。?