It is not possible to find the dbo column, the user-defined function, the dbo.FN_Split aggregate, or the name is ambiguous

I have the following function that takes a CSV and a divider and splits it

ALTER FUNCTION [dbo].[FN_Split] (@String varchar(max), @Delimiter char(1))      
returns @temptable TABLE (orderId int,items varchar(max))        
as        
begin        
   declare @idx int   
   declare @i int=0     
   declare @slice varchar(8000)        
   declare @orderId int = 0 --<added a counter

    select @idx = 1        
        if len(@String)<1 or @String is null  return        

   while @idx!= 0        
   begin        
       set @idx = charindex(@Delimiter,@String)        
       if @idx!=0        
           set @slice = left(@String,@idx - 1)        
       else        
          set @slice = @String        

       if(len(@slice)>0)   
           insert into @temptable(orderId, Items) values(@orderId, @slice)        
       set @orderId = @orderId+1 --<increment the counter

       set @String = right(@String,len(@String) - @idx)        
       if len(@String) = 0 break        
   end    
return        
end

& a stored procedure like this one that uses the above function and inserts the result into the database:

ALTER PROCEDURE dbo.StoredProcedure3
(
 --@tableName nvarchar(max),
 @p_SourceText nvarchar(max),
 @p_Delimeter nvarchar(100)=','
)

AS
BEGIN
DECLARE @sql nvarchar(max)
--select * from fn_ParseText2Table(@p_SourceText, @p_Delimeter)
--insert into Person values (@sql)
declare @i int=0
DECLARE @max int=3

while @i<=@max
begin
if @i=0
begin
set @sql='insert into Person values( select items from'+dbo.FN_Split(@p_SourceText,  
 @p_Delimeter)+ 'as where orderId ='+0+')'
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 

But after the procedure, I get the following error: It is impossible to find either the "dbo" column, the user-defined function, the set "dbo.FN_Split", or the name is ambiguous. No lines are affected. (0 rows returned)

Please help get out of it ...

0
source share
3

, create script .

-, @astander, .

, . sql, . , :

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

:

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

, .

+1

,

:

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

In my case, it was really a feature missing when exporting data from one database to another. Cannot find in destination database> Functions> Scalar Function. Then I created [dbo]. [Equals], and it worked. (copied from the source database)

0
source

Source: https://habr.com/ru/post/1611294/


All Articles