开发者

Calculate the number of hours a ticket is open, using SQL [duplicate]

This question already has an answer here: Closed 11 years ago.

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜