create procedure c_dzh_assignOwner_Distribution(@handleby char(6))
as
begin
declare
@peo_staff char(6)
,@peo_assigncount int
,@peo_rolegroup char(6)
,@peo_objectivetype char(6)
,@midvar1 int
,@customer_guid char(36)
,@newguid char(36)
,@custlists varchar(100)
declare cur_sor1 cursor for
select cur_staff,assigncount,cur_rolegroup,objectivetype_id
from c_dzh_assigninfo
where handleby=@handleby
open cur_sor1
fetch next from cur_sor1 into @peo_staff,@peo_assigncount,@peo_rolegroup,@peo_objectivetype
/* Pos 1 */
while @@fetch_status=0
set @midvar1=0 -- 这句应该在 Pos 1 位置上吧? 或者 Pos 1'?
begin
/* Pos 1' */
declare cur_sor2 cursor for
select customer_guid
from c_dzh_Owner_Distribution
where handleby=@handleby
open cur_sor2
fetch next from cur_sor2 into @customer_guid
while @@fetch_status=0
begin
set @newguid=newid()
insert into objective (
objective_guid
,objectivetype_id
,handleby_id
,handlegroup_id
,expireddate
,customer_guid
,objectivestatus
,createdby
,createddate
,modifiedby
,modifieddate)
values (
@newguid
,@peo_objectivetype
,@peo_staff
,@peo_rolegroup
,'2050-01-01 00:00:00'
,@customer_guid
,'OPEN'
,@handleby
,getdate()
,@handleby
,getdate())
insert into oblist (
oblist_guid
,objective_guid
,objectivetype_id
,expectstarttime
,expectendtime
,obstatus
,max_attempt
,handleby_id
,handlegroup_id
,createdby
,createddate
,modifiedby
,modifieddate)
values (
newid()
,@newguid
,@peo_objectivetype
,getdate()
,'2050-01-01 00:00:00'
,'OPEN'
,'5000'
,@peo_staff
,@peo_rolegroup
,@handleby
,getdate()
,@handleby
,getdate())
update c_dzh_Owner_Distribution set
flag=1
where customer_guid=@customer_guid
and handleby=@handleby
and flag=0
update customer set
owner=@peo_staff
where customer_guid=@customer_guid
update ''+@custlists+'' set
flagassign=1
where customer_guid=@customer_guid
set @midvar1=@midvar1+1
fetch next from cur_sor2 into @customer_guid
end
/* 下面这个段落: 当@midvar1!=@peo_assigncount时,无法进行Fetch next, 如何从cur_sor1 中取得数据呢? */
if(@midvar1=@peo_assigncount) begin
fetch next from cur_sor1 into @peo_staff,@peo_assigncount,@peo_rolegroup,@peo_objectivetype
end
/* Pos 2 */
end
close @cur_sor1 -- 应该是 close cur_sor1
deallocate @cur_sor1 -- 应该是 deallocate cur_sor1
/* 下面这两行 Pos 2 位置*/
close @cur_sor2 -- 应该是 close cur_sor2
deallocate @cur_sor2 -- 应该是 deallocate cur_sor2
end
解决方案 »
- mssqlserver触发器
- 如何利用sql server 2005全文索引 检索 xml类型 列中的 文字?
- 简单一问高手,关于存储过程。顶者有分
- 如何导入Excel表中的部分行数据?
- 请教!请教!课程表的数据库的建立
- 求SQL语句:求数据库内各表大小,并排序列出.
- 在Oracle中有字典视图等,可以方便查找用户建的表、字段等,在Sqlserver中如何查询?
- 还是一个老问题。请各位神仙高手帮帮忙啊!!!
- 觉的不可能实现,两个表怎么合并啊???
- sql 语句查询
- 小菜求助:sql2000的一个查询语句(对各位来说很简单,我不会。。)
- 急!急!急!程序通过ADO访问SQL Server数据库,客户端电脑每次开机后需要登录一下服务器,才能连接,否则连接失败,怎么解决?谢谢!!!
/* 下面这个段落: 当@midvar1!=@peo_assigncount时,无法进行Fetch next, 如何从cur_sor1 中取得数据呢? */
if(@midvar1=@peo_assigncount) begin
fetch next from cur_sor1 into @peo_staff,@peo_assigncount,@peo_rolegroup,@peo_objectivetype
end
那这个地方该怎么弄呢???
as
begin
declare
@peo_staff char(6)
,@peo_assigncount int
,@peo_rolegroup char(6)
,@peo_objectivetype char(6)
,@midvar1 int
,@customer_guid char(36)
,@newguid char(36)
,@custlists varchar(100)
-- cur_sor1 对c_dzh_assigninfo 在handleby=@handleby条件下的每条记录进行遍历
declare cur_sor1 cursor for
select cur_staff,assigncount,cur_rolegroup,objectivetype_id
from c_dzh_assigninfo
where handleby=@handleby
open cur_sor1
fetch next from cur_sor1 into @peo_staff,@peo_assigncount,@peo_rolegroup,@peo_objectivetype
/* Pos 1 */
while @@fetch_status=0
begin
set @midvar1=0
-- cur_sor2 对c_dzh_Owner_Distribution 在handleby=@handleby条件下的每条记录进行遍历
-- 取得每个customer_guid
declare cur_sor2 cursor for
select customer_guid
from c_dzh_Owner_Distribution
where handleby=@handleby
open cur_sor2
fetch next from cur_sor2 into @customer_guid
while @@fetch_status=0
begin
-- 赋值、变更
set @newguid=newid()
insert into objective (
objective_guid
,objectivetype_id
,handleby_id
,handlegroup_id
,expireddate
,customer_guid
,objectivestatus
,createdby
,createddate
,modifiedby
,modifieddate)
values (
@newguid
,@peo_objectivetype
,@peo_staff
,@peo_rolegroup
,'2050-01-01 00:00:00'
,@customer_guid
,'OPEN'
,@handleby
,getdate()
,@handleby
,getdate())
insert into oblist (
oblist_guid
,objective_guid
,objectivetype_id
,expectstarttime
,expectendtime
,obstatus
,max_attempt
,handleby_id
,handlegroup_id
,createdby
,createddate
,modifiedby
,modifieddate)
values (
newid()
,@newguid
,@peo_objectivetype
,getdate()
,'2050-01-01 00:00:00'
,'OPEN'
,'5000'
,@peo_staff
,@peo_rolegroup
,@handleby
,getdate()
,@handleby
,getdate())
update c_dzh_Owner_Distribution set
flag=1
where customer_guid=@customer_guid
and handleby=@handleby
and flag=0
update customer set
owner=@peo_staff
where customer_guid=@customer_guid
update ''+@custlists+'' set
flagassign=1
where customer_guid=@customer_guid
set @midvar1=@midvar1+1
fetch next from cur_sor2 into @customer_guid
end
close cur_sor2
deallocate cur_sor2 /* 下面这个段落: 当@midvar1!=@peo_assigncount时,无法进行Fetch next, 如何从cur_sor1 中取得数据呢? */
-- 需要楼主确认
-- if(@midvar1=@peo_assigncount) begin
fetch next from cur_sor1 into @peo_staff,@peo_assigncount,@peo_rolegroup,@peo_objectivetype
-- end
end
close cur_sor1
deallocate cur_sor1
end
create procedure c_dzh_assignOwner_Distribution(@handleby char(6))
as
begin
declare @peo_staff char(6),@peo_assigncount int,@peo_rolegroup char(6),@peo_objectivetype char(6),@midvar1 int,
@customer_guid char(36),@newguid char(36),@custlists varchar(100),@sql nvarchar(500)
declare cur_sor1 cursor for select cur_staff,assigncount,cur_rolegroup,objectivetype_id from c_dzh_assigninfo where handleby=@handleby
open cur_sor1 fetch next from cur_sor1 into @peo_staff,@peo_assigncount,@peo_rolegroup,@peo_objectivetype
while @@fetch_status=0
set @midvar1=0 -----------这句话应该放在begin里面
begin
declare cur_sor2 cursor for select customer_guid from c_dzh_Owner_Distribution where handleby=@handleby
open cur_sor2 fetch next from cur_sor2 into @customer_guid
while @@fetch_status=0
begin
select @newguid=newid()
insert into objective
(objective_guid,objectivetype_id,handleby_id,handlegroup_id,expireddate,
customer_guid,objectivestatus,createdby,createddate,modifiedby,modifieddate)
values
(@newguid,@peo_objectivetype,@peo_staff,@peo_rolegroup,'2050-01-01 00:00:00',
@customer_guid,'OPEN',@handleby,getdate(),@handleby,getdate())
insert into oblist
(oblist_guid,objective_guid,objectivetype_id,expectstarttime,expectendtime,obstatus,max_attempt,handleby_id,handlegroup_id,createdby,createddate,modifiedby,modifieddate)
values
(newid(),@newguid,@peo_objectivetype,getdate(),'2050-01-01 00:00:00','OPEN','5000',@peo_staff,@peo_rolegroup,@handleby,getdate(),@handleby,getdate())
update c_dzh_Owner_Distribution set flag=1 where customer_guid=@customer_guid and handleby=@handleby and flag=0
update customer set owner=@peo_staff where customer_guid=@customer_guid
set @sql='update '''+@custlists+''' set flagassign=1 where customer_guid='''+@customer_guid+''''
exec sp_executesql @sql
set @midvar1=@midvar1+1
fetch next from cur_sor2 into @customer_guid
end
if(@midvar1=@peo_assigncount)
begin
fetch next from cur_sor1 into @peo_staff,@peo_assigncount,@peo_rolegroup,@peo_objectivetype
end
end
close cur_sor1
deallocate cur_sor1
close cur_sor2
deallocate cur_sor2
end
create procedure c_dzh_assignOwner_Distribution(@handleby char(6))
as
begin
declare
@peo_staff char(6)
,@peo_assigncount int
,@peo_rolegroup char(6)
,@peo_objectivetype char(6)
,@midvar1 int
,@customer_guid char(36)
,@newguid char(36)
,@custlists varchar(100)
declare cur_sor1 cursor for
select cur_staff,assigncount,cur_rolegroup,objectivetype_id , customer_guid
from c_dzh_assigninfo a, c_dzh_Owner_Distribution b
where a.handleby=@handleby and b.handleby=@handleby
open cur_sor1
fetch next from cur_sor1 into @peo_staff,@peo_assigncount,@peo_rolegroup,@peo_objectivetype , @customer_guid
while @@fetch_status=0 begin
-- 赋值、变更
set @newguid=newid()
insert into objective (
objective_guid
,objectivetype_id
,handleby_id
,handlegroup_id
,expireddate
,customer_guid
,objectivestatus
,createdby
,createddate
,modifiedby
,modifieddate)
values (
@newguid
,@peo_objectivetype
,@peo_staff
,@peo_rolegroup
,'2050-01-01 00:00:00'
,@customer_guid
,'OPEN'
,@handleby
,getdate()
,@handleby
,getdate())
insert into oblist (
oblist_guid
,objective_guid
,objectivetype_id
,expectstarttime
,expectendtime
,obstatus
,max_attempt
,handleby_id
,handlegroup_id
,createdby
,createddate
,modifiedby
,modifieddate)
values (
newid()
,@newguid
,@peo_objectivetype
,getdate()
,'2050-01-01 00:00:00'
,'OPEN'
,'5000'
,@peo_staff
,@peo_rolegroup
,@handleby
,getdate()
,@handleby
,getdate())
update c_dzh_Owner_Distribution set
flag=1
where customer_guid=@customer_guid
and handleby=@handleby
and flag=0
update customer set
owner=@peo_staff
where customer_guid=@customer_guid
update ''+@custlists+'' set
flagassign=1
where customer_guid=@customer_guid
fetch next from cur_sor1 into @peo_staff,@peo_assigncount,@peo_rolegroup,@peo_objectivetype , @customer_guid
end
close cur_sor1
deallocate cur_sor1
end 请LZ试试
...
update ''+@custlists+'' set
flagassign=1
where customer_guid=@customer_guid
...
: 想更新的是什么表?
create procedure c_dzh_assignOwner_Distribution(@handleby char(6))
as
begin
select
objective_guid = newid()
,objectivetype_id = objectivetype_id
,handleby_id = cur_staff
,handlegroup_id = cur_rolegroup
,expireddate = '2050-01-01 00:00:00'
,customer_guid = customer_guid
,objectivestatus = 'OPEN'
,createdby = @handleby
,createddate = getdate()
,modifiedby = @handleby
,modifieddate = getdate()
into #objective
from c_dzh_assigninfo a, c_dzh_Owner_Distribution b
where a.handleby=@handleby and b.handleby=@handleby insert into objective
select
objective_guid
,objectivetype_id
,handleby_id
,handlegroup_id
,expireddate
,customer_guid
,objectivestatus
,createdby
,createddate
,modifiedby
,modifieddate
from #objective
insert into oblist
select
oblist_guid = newid()
,objective_guid
,objectivetype_id
,expectstarttime = getdate()
,expectendtime = '2050-01-01 00:00:00'
,obstatus = 'OPEN'
,max_attempt = '5000'
,handleby_id
,handlegroup_id
,createdby
,createddate
,modifiedby
,modifieddate
from #objective update c_dzh_Owner_Distribution set
flag=1
where handleby=@handleby
and flag=0 update customer set
owner=@peo_staff
from customer a
join #objective b
on a.customer_guid=b.customer_guid /* 这段的逻辑不清楚,未加处理
update ''+@custlists+'' set
flagassign=1
where customer_guid=@customer_guid
*/
drop table #objective
end