Calculate the number of hours a ticket is open, using SQL [duplicate]
Possible Duplicate:
Calculate open hours
I am using a SQL query to calculate the "open hours" for a complaint from it's complaintdate
until now.
Select datediff(hour,
Convert(DateTime,
Convert(DateTime,
Convert(nVarChar, cast(complaintdate as datetime),开发者_开发知识库 101)
) + '' +
Convert(varchar, complainttime, 114)
),
dateadd(mi, 330, GETUTCDATE())
) as [Open Hours] from complaintregister
and getting a column
Open Hours
15139
15070
15070
15070
15070
100
300
200
400
I want to get open hours only more than 500
Here's a simple approach:
select * from ( Select datediff(hour,
Convert(DateTime,
Convert(DateTime,
Convert(nVarChar, cast(complaintdate as datetime), 101)
) + '' +
Convert(varchar, complainttime, 114)
),
dateadd(mi, 330, GETUTCDATE())
) as [Open Hours] from complaintregister ) t where t.[Open Hours]>500
精彩评论