Cannot find either column “dbo” or the user-defined function or aggregate “dbo.FN_Split”, or the name is ambiguous

前端 未结 3 1445
夕颜
夕颜 2021-01-15 18:11

I have following function which accepts the CSV & delimeter & splits it

ALTER FUNCTION [dbo].[FN_Split] (@String varchar(max), @Delimiter char(1))           


        
相关标签:
3条回答
  • 2021-01-15 18:27

    I think to clarify the comment from astander

    try your code like this :

    while @i<=@max
    begin
    if @i=0
    begin
    set @sql='insert into Person select items from dbo.FN_Split(@p_SourceText,  
     @p_Delimeter) where orderId = 00'
    end
    
     else
      begin
       if @i=(@max-1)
        begin
     set @sql=@sql+'UNION select items from dbo.FN_Split(@p_SourceText,
                      @p_Delimeter) where orderId ='+@i
        end
     else
      begin
       set @sql=@sql+'UNION select items from dbo.FN_Split(@p_SourceText,        
                     @p_Delimeter) where orderId ='+@i UNION'
          end
       end
       set @i=@i+1
    end
    END 
    
    0 讨论(0)
  • 2021-01-15 18:35

    First, make sure you did run the create script in the correct database.

    Second, as @astander started mentioning, you are using the function results incorrectly.

    Your function returns a table, not a value. You'll need to execute the function as part of your sql statements, not during your build of ad hoc queries. For example, this code:

     set @sql=@sql+'UNION select items from'+ dbo.FN_Split(@p_SourceText,
                      @p_Delimeter)+' where orderId ='+@i+')'
    

    would become:

    set @sql = @sql+'UNION select items from dbo.FN_Split(' + @p_SourceText +', ' +
                      @p_Delimeter + ') where orderId =' + @i + ')'
    

    Make similar changes everywhere you are currently referencing the function.

    0 讨论(0)
  • 2021-01-15 18:40

    For my case it was really a function missing when i exported data from one database to another. Can not be found in the destination database > Functions > Scalar-valued Functions. Then i created [dbo].[equals] and it worked. (copied from source database)

    0 讨论(0)
提交回复
热议问题