本文介绍了如何在 sql server 2008 中调用标量函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建了一个标量函数,它已成功创建,但是当我使用 select 语句调用该函数时,它显示无效的对象名称dbo.fun_functional_score".
I have created a Scalar Functions, it was created successfully, but when I call the function using select statement, it says Invalid object name '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'."
both showing error "Invalid object name 'dbo.fun_functional_score'."
我出错的地方.谁能帮帮我...
where i made error . can anyone help me...
推荐答案
你的语法是表值函数的,它返回一个结果集,可以像表一样查询.对于标量函数做
Your syntax is for table valued function which return a resultset and can be queried like a table. For scalar function do
select dbo.fun_functional_score('01091400003') as [er]
这篇关于如何在 sql server 2008 中调用标量函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!