title: Cannot find either column “dbo” or the user-defined function or aggregate “dbo.udf_RemoveHTMLTags”, or the name is ambiguous
body: <p>I am trying to create a sql script and run . I am seeing the compiler error Cannot find either column “dbo” or the user-defined function or aggregate “dbo.udf_RemoveHTMLTags”, or the name is ambiguous.On running i get the following error The multi-part identifier "#tempriskdesc.risk_id" could not be bound.</p>
  
  <pre><code>SET ANSI_NULLS ON
  SET QUOTED_IDENTIFIER ON
  go
  
  CREATE FUNCTION [dbo].[udf_RemoveHTMLTags]
      (@HTMLText VARCHAR(4000))
  RETURNS VARCHAR(4000)
  AS
  BEGIN
      DECLARE @Start INT
      DECLARE @End INT
      DECLARE @Length INT
  
      SET @Start = CHARINDEX('&lt;', @HTMLText)
      SET @End = CHARINDEX('&gt;', @HTMLText, CHARINDEX('&lt;', @HTMLText))
      SET @Length = ( @End - @Start ) + 1
  
      WHILE @Start &gt; 0 AND @End &gt; 0 AND @Length &gt; 0
      BEGIN
           SET @HTMLText = STUFF(@HTMLText, @Start, @Length, '')
           SET @Start = CHARINDEX('&lt;', @HTMLText)
           SET @End = CHARINDEX('&gt;', @HTMLText, CHARINDEX('&lt;', @HTMLText))
           SET @Length = ( @End - @Start ) + 1
      END
      RETURN LTRIM(RTRIM(@HTMLText))
  END
  </code></pre>
  
  <p>I then try to use that function in this manner:</p>
  
  <pre><code>BEGIN TRY
      CREATE TABLE #tempriskdesc
              (risk_id INTEGER ,
               risk_desc VARCHAR(4000))
  
      INSERT INTO #tempriskdesc
         SELECT 
            p.risk_id ,
            [dbo].[udf_RemoveHTMLTags](SUBSTRING(p.risk_descr, 1, 4000))
         FROM    
            PROJRISK p
  
      UPDATE PROJRISK
      SET risk_desc = #tempriskdesc.risk_desc
      WHERE #tempriskdesc.risk_id = PROJRISK.risk_id
  
      DROP TABLE #tempriskdesc
  END TRY
  BEGIN CATCH
      DECLARE @ErrorMessage NVARCHAR(4000) ,
              @ErrorSeverity INTEGER ,
              @ErrorState INTEGER ,
              @ErrorNumber INTEGER;
      SELECT  @ErrorMessage = ERROR_MESSAGE() ,
              @ErrorSeverity = ERROR_SEVERITY() ,
              @ErrorState = ERROR_STATE() ,
              @ErrorNumber = ERROR_NUMBER();
      RAISERROR (@ErrorMessage, @ErrorSeverity, @ErrorState );
  END CATCH   
  </code></pre>