游标,存储过程,以及临时表
需要在SQL端实现业务逻辑,NND (-_-")
代码一:
ALTER proc [dbo].[tt_select] @Id bigint as select PlanId,FGPartNo,p_FGName from backflush where Id<@Id |
代码二:
Declare @Id bigint Set @Id=12 Declare @PlanId nvarchar(100),@FGPartNo nvarchar(100),@FGName nvarchar(100) --确保临时表已经被删除了 IF object_id( 'tempdb..#t_bf_tmp' ) IS NOT NULL Begin Drop Table #t_bf_tmp End --定义临时表 Create Table #t_bf_tmp ( PlanId nvarchar(50), FGPartNo nvarchar(50) , p_FGName nvarchar(50) ) --将存储过程的执行结果添加到临时表 Insert Into #t_bf_tmp Exec tt_select @Id --使用游标遍历临时表,并做对于处理 Declare MyCursor Cursor For Select * from #t_bf_tmp For Read Only Open MyCursor Fetch next From MyCursor Into @PlanId,@FGPartNo,@FGName while(@@FETCH_STATUS = 0) Begin print @PlanId Fetch next From MyCursor Into @PlanId,@FGPartNo,@FGName End Close MyCursor Deallocate MyCursor Drop Table #t_bf_tmp |
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步