码迷,mamicode.com
首页 > 其他好文 > 详细

存储过程

时间:2016-08-02 08:52:03      阅读:157      评论:0      收藏:0      [点我收藏+]

标签:

技术分享
-- =============================================
-- Author:        <Author,,Name>
-- Create date: <Create Date,,>
-- Description:    <Description,,>
-- =============================================
--规格、规格值数据迁移
/*
*每个商户的规格只有两种:1.默认规格 2.颜色
*且默认规格有值,产品项才会生效。颜色规格可为空
*/
ALTER PROCEDURE [dbo].[SpecificationTBTransfer]
AS
    declare @CreateTime datetime=getdate()
    declare @SpecificationSortId int =1    
    declare @MerchantId int     
    declare get_merchant_id cursor for
        select 
        [MiLaiShopTemp].[dbo].[GetMerchantIdByWWW](www) MerchantId
        FROM [BingSNS_Client].[dbo].[BingSNS_NewsList]
        where [MiLaiShopTemp].[dbo].[GetMerchantIdByWWW](www) is not null
        group by [MiLaiShopTemp].[dbo].[GetMerchantIdByWWW](www)
BEGIN
    --为每个商户创建两个规格(默认规格、颜色规格)
    Begin Transaction
    open get_merchant_id
    FETCH NEXT FROM get_merchant_id INTO @MerchantId
    WHILE @@FETCH_STATUS = 0
    begin
        set @SpecificationSortId=1    
        --新建默认规格
        insert into [MiLaiShopTemp].[dbo].[SpecificationTB]
        (Title,CreateTime,MerchantTBID,SortID)
        values
        (默认,@CreateTime,@MerchantId,@SpecificationSortId)
        set @SpecificationSortId=@SpecificationSortId+1        
        --新建颜色规格
        insert into [MiLaiShopTemp].[dbo].[SpecificationTB]
        (Title,CreateTime,MerchantTBID,SortID)
        values
        (颜色,@CreateTime,@MerchantId,@SpecificationSortId)
        set @SpecificationSortId=@SpecificationSortId+1    
        FETCH NEXT FROM get_merchant_id INTO @MerchantId
    end    
    close get_merchant_id
    commit transaction                
END
View Code

 

存储过程

标签:

原文地址:http://www.cnblogs.com/liandy0906/p/5727945.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!