使用CTE进行无效的浮点运算(Invalid floating point operation with CTE)

编程入门 行业动态 更新时间:2024-10-18 01:32:28
使用CTE进行无效的浮点运算(Invalid floating point operation with CTE)

我收到此代码发生了无效的浮点运算错误。 它告诉我问题是CTE开始的问题。 如果我没有SQRT功能,那么一切正常,但是一旦我添加了SQRT,我就会收到错误。

我想要做的是通过平方数来摆脱负面。

declare @start_date date, @end_date date set @start_date = '2012/01/01' set @end_date = '2012/12/31'; with tbl1 as ( select strata, entranceID, sum(count)/count(*) as AverageCount from train where surveydate between '2012/01/01' and '2012/12/31' group by strata, entranceID ) select a.jobnumber, a.strata, a.EntranceID, Count, b.AverageCount, count - AverageCount , CASE WHEN AverageCount = 0 then 0 ELSE SQRT(count - AverageCount) END as A

I'm getting An invalid floating point operation occurred error with this code. It's telling me that the problem is on line where the CTE starts. If I don't have the SQRT function, then everything work fine, but as soon as I add the SQRT I get the error.

What I'm trying to do is to get rid of the negative by squaring the number.

declare @start_date date, @end_date date set @start_date = '2012/01/01' set @end_date = '2012/12/31'; with tbl1 as ( select strata, entranceID, sum(count)/count(*) as AverageCount from train where surveydate between '2012/01/01' and '2012/12/31' group by strata, entranceID ) select a.jobnumber, a.strata, a.EntranceID, Count, b.AverageCount, count - AverageCount , CASE WHEN AverageCount = 0 then 0 ELSE SQRT(count - AverageCount) END as A

最满意答案

在表达式中:

SQRT(count - AverageCount)

count的值必须> = AverageCount。

这可能不适用于您的测试数据。

考虑使用:

SQRT (ABS(count - AverageCount))

相反,如果这在你的情况下是有道理的。

In the expression:

SQRT(count - AverageCount)

The value of count has to be >= AverageCount.

This may not be true for your test data.

Consider using :

SQRT (ABS(count - AverageCount))

Instead, If that makes sense in your case.

更多推荐

本文发布于:2023-07-22 09:45:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1219094.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:浮点   Invalid   CTE   operation   point

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!