博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
游标简单的使用
阅读量:5037 次
发布时间:2019-06-12

本文共 1994 字,大约阅读时间需要 6 分钟。

GO

/****** Object:  StoredProcedure [dbo].[UP_Job_UpdatePromotionBeginInfo]    Script Date: 08/19/2014 19:02:11 ******/

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

 ALTER PROCEDURE [dbo].[UP_Job_UpdatePromotionBeginInfo]
AS
    BEGIN 
        DECLARE MyFirstCursor CURSOR
        FOR
            SELECT  a.ProductProID ,
                    a.productItemid ,
                    p.productid ,
                    a.ProPromKindID ,
                    a.PromPrice,
                    --新添加五个字段
                    a.IsLimitBuyStatus,
                    a.LimitBuyPersonalCount,
                    a.LimitBuyCount,
                    a.bDate,
                    a.eDate
            FROM    ProductPro a
                    INNER JOIN productitem item ON a.productitemid = item.productitemid
                    INNER JOIN product p ON p.productid = item.productid
            WHERE   a.BDate <= GETDATE()
                    AND a.EDate >= GETDATE()
                    AND a.[State] = 0

        OPEN MyFirstCursor

        DECLARE @ProductProID INT

        DECLARE @productItemid INT
        DECLARE @productid INT
        DECLARE @ProPromKindID INT
        DECLARE @num INT 
        DECLARE @PromPrice MONEY
        --新添加五个字段
        DECLARE @IsPur INT
        DECLARE @OnePurNum INT
        DECLARE @TotalPurNum INT
        DECLARE @StartDate DATETIME
        DECLARE @LastDate DATETIME
        FETCH NEXT FROM MyFirstCursor INTO @ProductProID, @productItemid, @productid, @ProPromKindID, @PromPrice,@IsPur,@OnePurNum,@TotalPurNum,@StartDate,@LastDate
        WHILE ( @@FETCH_STATUS = 0 )
            BEGIN
   --修改ProductPro 状态     
                UPDATE  dbo.ProductPro
                SET     [State] = 1
                WHERE   ProductProID = @ProductProID

                UPDATE TOP ( 1 )

                        product
                SET     ProductAttributeID = @ProPromKindID ,
                        Price = @PromPrice ,
                        Price2 = @PromPrice
                WHERE   productid = @productid
         
                UPDATE TOP ( 1 )
                        productitem
                SET     OldPrice = price ,
                        price = @PromPrice
                        --新添加五个字段
                        ,IsPur=@IsPur
                        ,OnePurNum=@OnePurNum
                        ,TotalPurNum=@TotalPurNum
                        ,StartDate=@StartDate
                        ,LastDate=@LastDate
                WHERE   productitemid = @productItemid

    --xia 20140218 限制团购数量 改动

                SELECT  @num = LimitNum
                FROM    dbo.ProductPro
                WHERE   ProductProID = @ProductProID
                UPDATE  productitem
                SET     StoreNum = @num
                WHERE   ProductItemID = @productItemid
               
           
    
         
            --读取下一行
                FETCH NEXT FROM MyFirstCursor INTO @ProductProID,
                    @productItemid, @productid, @ProPromKindID, @PromPrice
            END
    --关闭游标
        CLOSE MyFirstCursor
    --删除游标
        DEALLOCATE MyFirstCursor
   
  
    END
 
   

 

转载于:https://www.cnblogs.com/yexinw/p/3922910.html

你可能感兴趣的文章
【oracle】dmp导数据库
查看>>
微软 SqlHelper代码、功能、用法介绍:高效的组件
查看>>
丰子恺-《豁然开朗》
查看>>
JavaScript 对象
查看>>
原生js轮播图(面向对象)
查看>>
数据分析软件及spss简单操作
查看>>
自定义通信协议
查看>>
Unity3d--Space Shooter(官方教程)--学习感想(3)
查看>>
java中Collections.sort()方法实现集合排序
查看>>
nodejs笔记之事件循环
查看>>
JVM之垃圾收集器
查看>>
Windows下R画图举例
查看>>
php-fpm 重启 nginx单独配置 重启
查看>>
JS正则表达式RegExp 对象
查看>>
Springboot
查看>>
go语言之进阶篇值语义和引用语义
查看>>
go语言之进阶篇无缓冲channel
查看>>
linux 常见命令
查看>>
func_get_args 笔记
查看>>
hdu 2881(LIS变形)
查看>>