title: how to call scalar function in sql server 2008
body: <p>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'.</p>
  
  <p>my function:</p>
  
  <pre><code> 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
  </code></pre>
  
  <p>i used this select to call </p>
  
  <pre><code> select * from dbo.fun_functional_score('01091400003') as [er]
  </code></pre>
  
  <p>or </p>
  
  <pre><code> select * from dbo.fun_functional_score('01091400003') 
  </code></pre>
  
  <p>both showing error "Invalid object name 'dbo.fun_functional_score'.
  "</p>
  
  <p>where i made error . can anyone help me...</p>