Sql server 如何获得登录和注销之间的小时差
如何获取以小时为单位的时间以及登录和注销时间之间的小时差 我使用了以下查询:Sql server 如何获得登录和注销之间的小时差,sql-server,sql-server-2008,sql-server-2008-r2,Sql Server,Sql Server 2008,Sql Server 2008 R2,如何获取以小时为单位的时间以及登录和注销时间之间的小时差 我使用了以下查询: select LoginDateTime,LogoutDateTime from Fleet_DriverQueueList 我在下面附上了我的数据截图 尝试以下操作: SELECT ISNULL(DATEDIFF(HOUR, LoginDateTime, LogoutDateTime), 1) FROM Table 请尝试以下操作: SELECT ISNULL(DATEDIFF(HOUR, LoginDateTi
select LoginDateTime,LogoutDateTime from Fleet_DriverQueueList
我在下面附上了我的数据截图
尝试以下操作:
SELECT ISNULL(DATEDIFF(HOUR, LoginDateTime, LogoutDateTime), 1) FROM Table
请尝试以下操作:
SELECT ISNULL(DATEDIFF(HOUR, LoginDateTime, LogoutDateTime), 1) FROM Table
只需使用DATEDIFF函数。像这样:
SELECT
DATEDIFF(HOUR,[LoginDateTime],[LogoutDateTime])
FROM
YourTable
只需使用DATEDIFF函数。像这样:
SELECT
DATEDIFF(HOUR,[LoginDateTime],[LogoutDateTime])
FROM
YourTable
更好地使用几分钟甚至几秒钟,它将更准确:
select DATEDIFF(minute,LoginDateTime,COALESCE(LogoutDateTime,GETDATE()))/60.00,
CASE WHEN LogoutDateTime IS NULL THEN 'Active' ELSE 'Not Active' END [Status]
from Fleet_DriverQueueList
select DATEDIFF(second,LoginDateTime,COALESCE(LogoutDateTime,GETDATE()))/3600.00,
CASE WHEN LogoutDateTime IS NULL THEN 'Active' ELSE 'Not Active' END [Status]
from Fleet_DriverQueueList
select DATEDIFF(hour,LoginDateTime,COALESCE(LogoutDateTime,GETDATE()))/3600.00,
CASE WHEN LogoutDateTime IS NULL THEN 'Active' ELSE 'Not Active' END [Status]
from Fleet_DriverQueueList
更好地使用几分钟甚至几秒钟,它将更准确:
select DATEDIFF(minute,LoginDateTime,COALESCE(LogoutDateTime,GETDATE()))/60.00,
CASE WHEN LogoutDateTime IS NULL THEN 'Active' ELSE 'Not Active' END [Status]
from Fleet_DriverQueueList
select DATEDIFF(second,LoginDateTime,COALESCE(LogoutDateTime,GETDATE()))/3600.00,
CASE WHEN LogoutDateTime IS NULL THEN 'Active' ELSE 'Not Active' END [Status]
from Fleet_DriverQueueList
select DATEDIFF(hour,LoginDateTime,COALESCE(LogoutDateTime,GETDATE()))/3600.00,
CASE WHEN LogoutDateTime IS NULL THEN 'Active' ELSE 'Not Active' END [Status]
from Fleet_DriverQueueList
你可以使用Datediff函数,试试这个
Select Case when isnull(LogoutDateTime,'')='' then 'Active' else 'Not Active' end as Status,
Case when isnull(LogoutDateTime,'')=''
then DATEDIFF(HH,LoginDateTime,getdate())
else DATEDIFF(HH,LoginDateTime,LogoutDateTime) end as Period
from Fleet_DriverQueueList
你可以使用Datediff函数,试试这个
Select Case when isnull(LogoutDateTime,'')='' then 'Active' else 'Not Active' end as Status,
Case when isnull(LogoutDateTime,'')=''
then DATEDIFF(HH,LoginDateTime,getdate())
else DATEDIFF(HH,LoginDateTime,LogoutDateTime) end as Period
from Fleet_DriverQueueList
您能否包含用于获取上述结果集的查询?如果
LogoutDateTime
为NULL
,您希望得到什么输出?如果LogoutDateTime
值为NULL
,则表示您希望从LoginDateTime
添加任何固定小时数?是单个用户的上述信息吗?能否包含用于获取上述结果集的查询?如果LogoutDateTime
为NULL,您希望得到什么输出?如果LogoutDateTime
值为NULL
,则表示您希望从LoginDateTime
添加任何固定小时数?以上是单个用户的信息吗?您能帮助我如何获取if driver active getdate()并显示小时数吗?您能帮助我如何获取if driver active getdate()吗请核对我的答案。如果您发现任何答案有帮助,请随时投票/接受。请检查我的答案。如果您发现任何答案都有帮助,请随意投票/接受。