游标可以嵌套使用吗?如果能谁能给个例子,我写不好。
问题点数:38、回复次数:3Top
1 楼goldg()回复于 2001-06-14 18:05:00 得分 0
我在SQL SERVER中写一个存储过程,写了半天总不对。那位大哥能给我个例子Top
2 楼yangzi(笨笨)回复于 2001-06-14 18:13:00 得分 38
游标可以嵌套使用。
不过你填充好游标以后,其基表会被lock。不可修改。
最好把你的存储过程贴出来,或把思路写出来。大家分析一下。
Top
3 楼goldg()回复于 2001-06-14 18:36:00 得分 0
CREATE PROCEDURE [sp_gxclhx_scje]/*将原材料消耗均摊到股线*/
@i_yf int /*月份*/
AS
DECLARE @s_cldm char(10), /*材料代码*/
@m_hyje money, /*原材料耗用金额*/
@s_gxdm char(12), /*股线代码*/
@f_scsl float, /*股线生产量*/
@f_pbxs float, /*配比系数*/
@f_gxqz float, /*股线全重*/
@f_gxqzhz float /*同种材料股线权重汇总*/
declare clscl_cur cursor for
select s_cldm,m_hyje from t_clxh where i_yf = @i_yf and s_cllx1 = '1'
open clscl_cur
fetch next from clscl_cur into @s_cldm,@m_hyje
while @@fetch_status <> -1
begin
select @f_gxqzhz = sum(t_gxclxh.f_scsl * t_gx.f_pbxs) from t_gx,t_gxclxh
where t_gx.s_gxdm = t_gxclxh.s_gxdm and t_gxclxh.s_cldm = @s_cldm and t_gxclxh.i_yf = @i_yf
declare gxscl_cur cursor for
select s_gxdm,f_scsl from t_gxclxh where s_cldm = @s_cldm and i_yf = @i_yf
open gxscl_cur
fetch next from gxscl_cur into @s_gxdm,@f_scsl
while @@fetch_status <> -1
begin
select @f_gxqz = t_gxclxh.f_scsl * t_gx.f_pbxs from t_gx,t_gxclxh
where t_gx.s_gxdm = t_gxclxh.s_gxdm and t_gxclxh.s_cldm = @s_cldm and t_gxclxh.s_gxdm = @s_gxdm
update t_gxclxh set m_scje = @m_hyje * @f_gxqz / @f_gxqzhz
where i_yf = @i_yf and s_gxdm = @s_gxdm
fetch next from gxscl_cur into @s_gxdm,@f_scsl
end
close gxscl_cur
deallocate gxscl_cur
fetch next from clscl_cur into @s_cldm,@m_hyje
end
close clscl_cur
deallocate clscl_cur
这是成本管理的一部分,t_clxh为原材料消耗,t_gxclxh为股线材料消耗。一种原材料可以用来生产多种股线。录入原材料消耗的金额,然后根据股线和原材料的对应关系和配比系数,将原材料的金额分摊到股线。逻辑思路上我还算清楚,就不知道怎么写。Top




