问题描述
我为营业时间计算制作了一个用户定义的函数.
I made a user-define function for business hours calculation.
这是我的 UDF.
当我使用以下语句进行测试时,
When I test using following statement,
它显示了正确的结果.
但是,我这样使用我的函数,
However, I use my function like this,
结果只显示NULL值.
the result shows only NULL value.
我尝试了 CONVERT,因为当我给出值 40 时它起作用,但它也显示空值.
I tried CONVERT because it worked when I give a value 40 but it also shows null values.
我该如何解决这个问题才能让我的 UDF 正常工作?为什么会发生这件事?我无法理解 Priority 和 40 之间有什么不同.
How can I fix this to work my UDF? Why this thing happen? I cannot understand what is different between Priority and 40.
提前致谢.
推荐答案
对于优先级 > 8.5 的值,这对我来说似乎很好:
For values of priority > 8.5, this seems to work fine for me:
产量:
如果我添加另一行的优先级 <8.5,例如:
If I add another row with a Priority < 8.5, e.g.:
然后将这一行添加到结果中:
Then this row is added to the result:
换句话说,如果函数逻辑让@CalculatedDate 未赋值,则该函数将输出NULL,如果@addDayCount = 0,就会发生这种情况.在您说的函数中:
In other words, the function will output NULL if the function logic leaves @CalculatedDate unassigned, which will happen if @addDayCount = 0. In the function you say:
因为@addDayCount 是一个 INT,试试这个:
Since @addDayCount is an INT, try this:
结果:
因此,因为@CalculatedDate 最初没有分配值,所以以下所有 DATEADD 操作都在执行 DATEADD(interval, number, NULL) ,但仍会产生 NULL.
So because @CalculatedDate isn't assigned a value initially, all of the following DATEADD operations are performing DATEADD(interval, number, NULL) which still yields NULL.
所以也许你需要为函数中的变量使用不同的数据类型...
So perhaps you need to use a different data type for the variables in the function...
这篇关于在 SELECT 语句中使用 UDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!