简体   繁体   English

T-SQL Azure流分析四舍五入到分钟

[英]T-SQL Azure Stream Analytics Rounding to Minute

I have the following SELECT clause in my Azure Stream Analytics Query: 我的Azure流分析查询中有以下SELECT子句:

SELECT DateAdd(mi, DateDiff(mi, 0, DateAdd(s, 30, Max(timecreated))), 0) as 'timestamp'

Which is giving the following error: 这给出了以下错误:

Second parameter of 'DateDiff' in expression 'DateDiff ( mi , 0 , DateAdd(s, 30, Max ( timecreated ) ) )' has invalid type 'bigint'. 表达式'DateDiff(mi,0,DateAdd(s,30,Max(timecreated)))'中'DateDiff'的第二个参数具有无效类型'bigint'。 'datetime' is expected. 'datetime'是预期的。

Admittedly, the code I'm using is copied from several similar threads on StackOverflow, such as T-SQL datetime rounded to nearest minute and nearest hours with using functions , but I've no idea what to change the 0 to in my scenario. 不可否认,我正在使用的代码是从StackOverflow上的几个类似线程中复制的,例如T-SQL日期时间四舍五入到最接近的分钟和使用函数的最近几小时 ,但我不知道在我的场景中将0更改为什么。

It should have auto cast the 0 from bigint to datetime, but there may be some quirks with the Azure version of T-SQL. 它应该从bigint自动转换为0到datetime,但是Azure版本的T-SQL可能存在一些怪癖。 Instead, use: 相反,使用:

SELECT DATEADD(mi, 
  DATEDIFF(mi, CAST('1900-01-01 00:00:00.000' AS DateTime), 
    DATEADD(s, 30, MAX(timecreated))),
  CAST('1900-01-01 00:00:00.000' AS DateTime)) as 'timestamp'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM