真心求助
下面一个函数搞了两天。。郁闷 ALTER FUNCTION [dbo].[get_pcsl]
(
-- Add the parameters for the function here
@ac_bm varchar(8),@ac_nbbm varchar(30),@an_sl int
)
RETURNS @fn_pcsl TABLE
(
PC varchar(12),
DJ decimal(12, 2),
SL decimal(15)
)
AS
Begin
Declare @nSl int;
Declare @cPc varchar(12);
Declare @nDj decimal(12,2);
-- Declare @nSl_tmp int;
Select @nSl=isnull(sum(sl),0) from g_sppc where bm=@ac_bm and nbbm=@ac_nbbm;
if @nSl<@an_sl
Begin
return;
End
if Cursor_Status('global','Cur')>0
Deallocate Cur
Declare Cur Cursor For
select PH,DJ,SL from g_sppc where bm=@ac_bm and nbbm=@ac_nbbm order by xh for update of sl
Open Cur
Fetch next From Cur Into @cPc,@nDj,@nSl
While @@fetch_status=0
Begin
if @nSl>=@an_sl
begin
insert into @fn_pcsl(PC,DJ,SL)
values(@cPc,@nDj,@an_Sl);
update g_sppc ----<-------------------------------这里问题
set SL=@nSl-@an_sl
where bm=@ac_bm and nbbm=@ac_nbbm and ph=@cPc;---< 改成 where current cursor of cur 报(消息 443,级别 16,状态 14,过程 get_pcsl,第 41 行
在函数内的 'UPDATE CURSOR' 中对带副作用的或依赖于时间的运算符的使用无效。)
set @an_sl=0;
end
else
begin
insert into @fn_pcsl(PC,DJ,SL)
values(@cPc,@nDj,@nSl);
set @an_sl=@an_sl-@nSl;
end
if @an_sl=0
return;
Fetch next From Cur Into @cPc,@nDj,@nSl
End
Close Cur
Deallocate Cur
if @an_SL<>0
delete @fn_pcsl;
RETURN
end;sql server 2005 编译出错如下
消息 443,级别 16,状态 15,过程 get_pcsl,第 41 行
在函数内的 'UPDATE' 中对带副作用的或依赖于时间的运算符的使用无效。
下面一个函数搞了两天。。郁闷 ALTER FUNCTION [dbo].[get_pcsl]
(
-- Add the parameters for the function here
@ac_bm varchar(8),@ac_nbbm varchar(30),@an_sl int
)
RETURNS @fn_pcsl TABLE
(
PC varchar(12),
DJ decimal(12, 2),
SL decimal(15)
)
AS
Begin
Declare @nSl int;
Declare @cPc varchar(12);
Declare @nDj decimal(12,2);
-- Declare @nSl_tmp int;
Select @nSl=isnull(sum(sl),0) from g_sppc where bm=@ac_bm and nbbm=@ac_nbbm;
if @nSl<@an_sl
Begin
return;
End
if Cursor_Status('global','Cur')>0
Deallocate Cur
Declare Cur Cursor For
select PH,DJ,SL from g_sppc where bm=@ac_bm and nbbm=@ac_nbbm order by xh for update of sl
Open Cur
Fetch next From Cur Into @cPc,@nDj,@nSl
While @@fetch_status=0
Begin
if @nSl>=@an_sl
begin
insert into @fn_pcsl(PC,DJ,SL)
values(@cPc,@nDj,@an_Sl);
update g_sppc ----<-------------------------------这里问题
set SL=@nSl-@an_sl
where bm=@ac_bm and nbbm=@ac_nbbm and ph=@cPc;---< 改成 where current cursor of cur 报(消息 443,级别 16,状态 14,过程 get_pcsl,第 41 行
在函数内的 'UPDATE CURSOR' 中对带副作用的或依赖于时间的运算符的使用无效。)
set @an_sl=0;
end
else
begin
insert into @fn_pcsl(PC,DJ,SL)
values(@cPc,@nDj,@nSl);
set @an_sl=@an_sl-@nSl;
end
if @an_sl=0
return;
Fetch next From Cur Into @cPc,@nDj,@nSl
End
Close Cur
Deallocate Cur
if @an_SL<>0
delete @fn_pcsl;
RETURN
end;sql server 2005 编译出错如下
消息 443,级别 16,状态 15,过程 get_pcsl,第 41 行
在函数内的 'UPDATE' 中对带副作用的或依赖于时间的运算符的使用无效。
不能更新库内实体表。