zoukankan      html  css  js  c++  java
  • 游标,存储过程,以及临时表

    需要在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
    
  • 相关阅读:
    php——验证身份证是否合法的函数
    php——离线执行任务
    代码整洁之道
    js自适应屏幕高度
    SSH Junit4测试
    Java Persistence with Hibernate
    SSH搭建
    js整理
    Hibernate 应用
    对学习的一点感想
  • 原文地址:https://www.cnblogs.com/wdfrog/p/2303071.html
Copyright © 2011-2022 走看看