2010-01-19 6 views
39

Hai ragazzi,non riesce a trovare né colonna "dbo" o la funzione definita dall'utente o di aggregazione "dbo.Splitfn", oppure il nome è ambiguo

io ve utilizzato la seguente funzione split,

CREATE FUNCTION dbo.Splitfn(@String varchar(8000), @Delimiter char(1))  
returns @temptable TABLE (items varchar(8000))  
as  
begin  
declare @idx int  
declare @slice varchar(8000)  

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(Items) values(@slice)  

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

end 

e ho usato questa funzione in una query ed è stato eseguito

ALTER PROCEDURE [dbo].[Employees_Delete] 
-- Add the parameters for the stored procedure here 
@Id varchar(50) 
AS 
BEGIN 
-- SET NOCOUNT ON added to prevent extra result sets from 
-- interfering with SELECT statements. 
SET NOCOUNT ON; 

-- Insert statements for procedure here 

if exists(select Emp_Id from Employee where Emp_Id=dbo.Splitfn(@Id,',')) 
begin 
    update Employee set Is_Deleted=1 where Emp_Id=dbo.Splitfn(@Id,',') 
    select 'deleted' as message 
end 
END 

ma quando ho excute mia procedura negozio dando valori dicono (1,2) ho ottenuto l'errore

Cannot find either column "dbo" or the user-defined 
function or aggregate "dbo.Splitfn", or the name is ambiguous. 

Ho controllato le mie funzioni di tabella valutate la funzione 'splitfn' c'era ma non so cosa sta andando storto? Qualsiasi suggerimento ..

risposta

64

È una funzione valutata a livello di tabella, ma la si utilizza come una funzione scalare.

Prova:

where Emp_Id IN (SELECT i.items FROM dbo.Splitfn(@Id,',') AS i) 

Ma ... considerano anche cambiare la funzione in un TVF linea, in quanto sarà un rendimento migliore.

+0

@Rob ha funzionato per me .. Come cambiarlo in un TVF in linea .. Plz mi guida –

+0

Ci sono molti esempi in giro. Eccone uno: http://sqlserverpedia.com/blog/sql-server-bloggers/splitting-a-delimited-string-part-1/ –

+0

Grazie per la risposta. Stavo avendo lo stesso problema e non riuscivo a capire per la vita di me quello che stava succedendo. Mi hai salvato un enorme mal di testa. – gsirianni

10

è necessario trattare un tavolo valutata UDF come una tabella, ad esempio, unirlo

select Emp_Id 
from Employee E JOIN dbo.Splitfn(@Id,',') CSV ON E.Emp_Id = CSV.items 
3

una risposta generale

select * from [dbo].[SplitString]('1,2',',') -- Will work 

ma

select [dbo].[SplitString]('1,2',',') -- will not work and throws this error 
0

Dal momento che le persone verranno da Google, assicurati di essere nel database giusto.

L'esecuzione di SQL nel database "master" restituirà spesso questo errore.

Problemi correlati