FETCH NEXT FROM deptCursor INTO @deptname,@deptsimplename,@distid,@deptuncode,@deptqueryno,@ifreport,@deptsort,@enable,@deptfloor,@deptcharacter,@caseSMSFlag,@deptType
while (@@FETCH_STATUS = 0)
begin
/*检索乡镇行政部门:如赵集镇,龙王乡...*/
---申明游标
Declare MM_CURSOR CURSOR
local FOR
Select DEPTID from t_department where ENABLE= ‘启用‘ and DISTID = 1 and deptType=0 and deptid !=250---demo,except 250 -- and PARENTID =288--and deptid not in (243,244)--and is_convenience=@tjType jc_dreaming
Order by DEPTCODE /**ONLY VALID DEPARTMENT */
-- 打开游标
open MM_CURSOR
--循环取出游标
FETCH NEXT FROM MM_CURSOR INTO @DeNo
while (@@FETCH_STATUS = 0)
BEGIN
set @deptcode = convert(varchar(20),cast(@deptcode as int)+1)
print(@deptcode)
INSERT INTO T_DEPARTMENT (deptcode, deptname, deptsimplename,distid, deptuncode,deptqueryno,ifreport,deptsort,enable,deptfloor,PARENTID,deptcharacter,caseSMSFlag,deptType)
FETCH NEXT FROM deptCursor INTO @deptname,@deptsimplename,@distid,@deptuncode,@deptqueryno,@ifreport,@deptsort,@enable,@deptfloor,@deptcharacter,@caseSMSFlag,@deptType
Select DEPTID from t_department where ENABLE= ‘启用‘ and DISTID = 1 and deptType=0 and deptid !=250---demo,except 250 -- and PARENTID =288--and deptid not in (243,244)--and is_convenience=@tjType jc_dreaming
Order by DEPTCODE /**ONLY VALID DEPARTMENT */
-- 打开游标
open MM_CURSOR
--循环取出游标
FETCH NEXT FROM MM_CURSOR INTO @DeNo
while (@@FETCH_STATUS = 0)
set @deptcode = convert(varchar(20),cast(@deptcode as int)+1) //把此行代码移至begin代码内即可
BEGIN
print(@deptcode)
INSERT INTO T_DEPARTMENT (deptcode, deptname, deptsimplename,distid, deptuncode,deptqueryno,ifreport,deptsort,enable,deptfloor,PARENTID,deptcharacter,caseSMSFlag,deptType)