2013-04-11 10 views
6

Bir işlevde bir Seç ifadesini kullanmaya çalışırken bir hata alıyorsunuz. Hata durumları:Alma hatası "Bir işlev içinde bulunan ifadeleri seçme, bir istemciye veriyi döndüremiyor"

Msg 444, Level 16, State 2, Prosedür JDE_GetWhereClause_test, Hat müşteriye veri döndüremez bir işlev içinde bulunan 26
seçin ifadeleri.

Herhangi bir fikir?

CREATE FUNCTION [dbo].[JDE_GetWhereClause_test] 
(
@tablename as varchar 
) 
RETURNS varchar(max) 
AS 
BEGIN 
-- Declare the return variable here 
Declare @ResultVar as varchar(max) 

-- Add the T-SQL statements to compute the return value here 

set @tablename = 'F0101' 
Declare @Sql nvarchar(max) 
Declare my_cur cursor for 
    SELECT fsuser FROM dbo.JDE_ExRowSecurity where fsuser = fsuser; 

Declare @fsuser as nchar(15) 
open my_cur; 
fetch next from my_cur; 
while @@fetch_status = 0 
    begin 
     fetch next from my_cur into @fsuser;  
     set @ResultVar += ',' + @fsuser; 
    end; 
close my_cur; 
deallocate my_cur; 

-- Return the result of the function 
RETURN @ResultVar 
END 
+0

, ikinci 'set @ResultVar' ile next' deyimi getirme takas olabilir ... bir şey gibi oynuyor deneyin ... 'olarak İlk sırayı atlar ve son satırı iki defa – Axarydax

cevap

9

arada
CREATE FUNCTION [dbo].[JDE_GetWhereClause_test] 
(
@tablename as varchar 
) 
RETURNS varchar(max) 
AS 
BEGIN 
    -- Declare the return variable here 
    Declare @ResultVar as varchar(max) 

    -- Add the T-SQL statements to compute the return value here 

    set @ResultVar = (select STUFF((SELECT ',', fsuser as [text()] 
        FROM dbo.JDE_ExRowSecurity 
        FOR XML PATH ('')), 1, 1, '') as blah) 

    -- Return the result of the function 
    RETURN @ResultVar 
END 

select 'Answer is: '+[dbo].[JDE_GetWhereClause_test]('whatever')

+0

hmm; Yaptığım oldukça karmaşık bir seçime sahibim ... burada belirttiğim basit bir versiyon. Her ne kadar geri dönüş tek bir büyük varchar alan olduğundan saklı bir prosedür yerine tha işlevine geçeceğim .... Yardımlarınız için teşekkürler. – Ankur

İlgili konular