简体   繁体   English

SQL 查询上的 datediff 错误,但根本不使用 datediff

[英]datediff error on SQL query but not using datediff at all

I'm getting this error:我收到此错误:

Msg 535, Level 16, State 0, Line 2消息 535,第 16 级,State 0,第 2 行
The datediff function resulted in an overflow. datediff function 导致溢出。 The number of dateparts separating two date/time instances is too large.分隔两个日期/时间实例的日期部分的数量太大。 Try to use datediff with a less precise datepart.尝试将 datediff 与不太精确的日期部分一起使用。

I am using SQL Server 2008. I am not using a datediff function but I get an overflow error above.我正在使用 SQL Server 2008。我没有使用datediff function 但上面出现溢出错误。 The query below works on one of my DB with the same structure, but it doesn't work on this database on a different server.下面的查询适用于我的一个具有相同结构的数据库,但它不适用于不同服务器上的该数据库。 Do I have to change some DB settings to get this query to work?我是否必须更改一些数据库设置才能使此查询正常工作?

SELECT [EventStamp]
      ,[AlarmState]
      ,[TagName]
      ,[Description]
      ,[Area]
      ,[Type]
      ,[Value]
      ,[CheckValue]
      ,[Priority]
      ,[Category]
      ,[Provider]
      ,[Operator]
      ,[DomainName]
      ,[UserFullName]
      ,[AlarmDuration]
      ,[User1]
      ,[User2]
      ,[User3]
      ,[EventStampUTC]
      ,[MilliSec]
      ,[OperatorNode]
  FROM [A2ALMDB].[dbo].[v_AlarmEventHistory2]
  WHERE [EventStamp] >= '2022-08-25' AND [EventStamp] <= '2022-08-26' 
  ORDER BY [EventStamp] ASC

the view you are using [A2ALMDB].[dbo].[v_AlarmEventHistory2] contains the DATEDIFF function and its overflowing either due to the reason there is NULL in the date or its extracting a date part which is overflowing its natural value limit.您正在使用的视图[A2ALMDB].[dbo].[v_AlarmEventHistory2]包含 DATEDIFF function 及其溢出,或者由于日期中存在 NULL 的原因或其限制提取日期部分溢出其自然值。

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

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