这个函数的最优程度如何
我即将实现这个函数来计算一些数字。
CREATE FUNCTION [dbo].[funLookupFTE] (@PFID int) RETURNS
VARCHAR(20) AS BEGIN
DECLARE @NumberOfFTE AS VARCHAR(20)
SET @NumberOfFTE = (SELECT SUM(CASE WHEN Hours <= 20 THEN 0.5 WHEN Hours > 20 THEN 1 END) AS FTECount
FROM tblPractitioners
WHERE PFID =
@PFID)
RETURN @NumberOfFTE
END
只是想看看它是否是最佳的,并且不会自行解决问题。
I'm about to implement this function to calculate some numbers.
CREATE FUNCTION [dbo].[funLookupFTE] (@PFID int) RETURNS
VARCHAR(20) AS BEGIN
DECLARE @NumberOfFTE AS VARCHAR(20)
SET @NumberOfFTE = (SELECT SUM(CASE WHEN Hours <= 20 THEN 0.5 WHEN Hours > 20 THEN 1 END) AS FTECount
FROM tblPractitioners
WHERE PFID =
@PFID)
RETURN @NumberOfFTE
END
Just trying to see if it's optimal and it won't take matters into its own hand.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果要在任何类型的查询中调用它,您最好使用子查询而不是用户定义的函数。
例如:
用户定义函数的性能可能非常差,但您确实需要使用子查询或 UDF 来比较执行计划,看看哪个更好。
If this is to be called in any sort of query, you're probably better off using a subquery instead of a user-defined function.
For example:
Performance of user-defined functions can be very poor, but you'll really need to compare the execution plans using a subquery or UDF to see which is better.