如何解决如何在SQL Server 2008中调用标量函数
您的语法适用于表值函数,该函数返回结果集,并且可以像表一样查询。对于标量函数
select dbo.fun_functional_score('01091400003') as [er]
解决方法
我已经创建了一个标量函数,它已成功创建,但是当我使用select语句调用该函数时,它说无效的对象名’dbo.fun_functional_score’。
我的功能:
ALTER function [dbo].[fun_functional_score] (@phy_id varchar(20))
returns varchar(50)
as
begin
declare @level_initial int,@level_current int
-- initial functional score
set @level_initial=(SELECT pflag.fun_level
FROM tbl_phy_demographic_details as [phy]
inner join tbl_all_purple_flag_level as [pflag] on phy.Demographic_id=pflag.Id
WHERE phy.Physicion_id=@phy_id
and pflag.visited_count=(select MAX(visited_count)-1 from tbl_all_purple_flag_level ))
-- current functional score
set @level_current=(SELECT pflag.fun_level
FROM tbl_phy_demographic_details as [phy]
inner join tbl_all_purple_flag_level as [pflag] on phy.Demographic_id=pflag.Id
WHERE phy.Physicion_id=@phy_id
and pflag.visited_count=(select MAX(visited_count) from tbl_all_purple_flag_level ))
--to calculate functional score
declare @fun_level varchar(20),@result varchar(50)
set @fun_level=@level_current-@level_initial;
if @fun_level = 0 set @result='Maintained'
if @fun_level = '-1' set @result='Minor Improvement'
if @fun_level = '-2' set @result='Moderate Improvement'
if @fun_level = '-3' set @result='Significant Improvement'
if @fun_level = '-4' set @result='Substantial Improvement'
if @fun_level = '1' set @result='Minor Reduction'
if @fun_level = '2' set @result='Moderate Reduction'
if @fun_level = '3' set @result='Significant Reduction'
if @fun_level = '4' set @result='Substantial Reduction'
return @result
end
我用这个选择来打电话
select * from dbo.fun_functional_score('01091400003') as [er]
或者
select * from dbo.fun_functional_score('01091400003')
两者都显示错误“无效的对象名称’dbo.fun_functional_score’。”
我哪里出错了。谁能帮我…
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。