这个函数究竟是出了什么问题?请教!
老田低代码 2005-08-26 05:53:50 我写了如下的函数,但是在调用的时候确出现了问题!
Create function CustPolicy(@CustID char(32))
returns nvarchar(1000)
As
Begin
declare @policyNO nvarchar(1000)
declare @PolicyNOTmp Nvarchar(50)
declare cur_Cust_Pol cursor for
select PolicyNO from policy where customerID=RTRIM(@CustID) /*这个查询语句绝对是没有问题*/
open cur_Cust_Pol
fetch cur_Cust_Pol into @PolicyNOTmp
if (@@fetch_status<>0)
Begin
close cur_Cust_Pol
deallocate cur_Cust_Pol
return @CustID /*但是每次调用的时候都到了这里就返回了呢,为什么啊?*/
end
while (@@fetch_status=0)
begin
set @PolicyNO=@PolicyNO+@PolicyNOTmp
fetch cur_Cust_Pol into @policyNOTmp
end
close cur_Cust_Pol
deallocate cur_Cust_Pol
return @policyNO
end