sql server 数据库循环(游标)

DECLARE @oneCycles varchar(50);

DECLARE Tey_Cursor CURSOR--定义游标

FOR (select  col_id from project_column where col_id in (@endId))--查出需要的集合放到游标中

OPEN Tey_Cursor;--打开游标

FETCH NEXT FROM Tey_Cursor INTO @oneCycles;--读取第一行数据

WHILE @@FETCH_STATUS = 0

BEGIN

DECLARE @ptt   varchar(50)---判断是否有下一级(二级)

select @ptt=COUNT(*) from project_column where col_parentid in (select col_id from project_column where col_id in (@endId))

 

if(@ptt!=0)

begin

---插入第二级 

insert into project_column (proj_id,proj_name,col_parentid,col_name,col_typeid,col_type_name,col_ico1_alt,col_ico2_alt,col_cover_img,col_background,col_btn1,col_btn2,col_info_btn1,col_info_btn2,col_title_img,col_description,list_orderby_col,list_orderby_type,updated,created,is_del,activate_txtcolor,default_txtcolor,tempid,temp_link,index_num,is_index,album_path,album_img_count,return_btn_activate,return_btn_default,checkbox_image,recommend_image1,recommend_image2,info_background,sortid,col_title_showtype,is_editor,auth_editor,vote_num,json)select  proj_id, proj_name, @ppq, col_name, col_typeid, col_type_name,col_ico1_alt,col_ico2_alt,col_cover_img,col_background,col_btn1,col_btn2,col_info_btn1,col_info_btn2,col_title_img,col_description,list_orderby_col,list_orderby_type, updated, created,is_del,activate_txtcolor,default_txtcolor, tempid, temp_link,index_num, is_index,album_path,album_img_count,return_btn_activate,return_btn_default,checkbox_image,recommend_image1,recommend_image2,info_background, sortid, col_title_showtype, is_editor, auth_editor, vote_num,json  from project_column where col_id in (@endId)

end

else

begin

print '第二级结束!';

end

--PRINT @UserId;

FETCH NEXT FROM Tey_Cursor INTO @oneCycles;--读取下一行数据

 END

CLOSE Tey_Cursor; --关闭游标

DEALLOCATE Tey_Cursor; --释放游标

posted @ 2021-05-27 16:41  猴猴手记  阅读(217)  评论(0编辑  收藏  举报
浏览器标题切换
浏览器标题切换end