生成服务卡会员卡号的存储过程

ALTER PROCEDURE [dbo].[GetCard_ID]
(@C_Number int=0,
@C_Type FLOAT,
@GETTimes varchar(30)

)
AS
BEGIN
    -- routine body goes here, e.g.
    -- SELECT 'Navicat for SQL Server'
    declare    @GetId int
    DECLARE @CARD_Ids VARCHAR(60)
    DECLARE @CARD_Guid uniqueidentifier
    set @card_guid=newid()
    if EXISTS(select CARD_ID from SERVER_CARD where CARD_TYPE=@C_Type and GETTIME=@gettimes )
    BEGIN     
    select @GetId=MAX(RIGHT(CARD_ID,4)) from SERVER_CARD  where CARD_TYPE=@C_Type and GETTIME=@gettimes
     WHILE @C_Number>0 
      BEGIN
        set @getid=@getid+1
        set @CARD_Ids='ws'+CONVERT(varchar(100),@GETTimes,23)+replace(right(str(@GetId),4),' ','0')
        INSERT INTO SERVER_CARD (CARD_ID,CARD_CUSTOMER_ID,sale_guid,GETTIME) VALUES (@card_ids,0,@card_guid,@gettimes)
        set @C_number=@C_number-1
        END
    END
    else
    BEGIN
      set @getid=0
      WHILE @C_Number>0 
      BEGIN
        set @getid=@getid+1
        set @CARD_Ids='ws'+CONVERT(varchar(100),@GETTimes,23)+replace(right(str(@GetId),4),' ','0')
        INSERT INTO SERVER_CARD (CARD_ID,CARD_CUSTOMER_ID,sale_guid,GETTIME) VALUES (@card_ids,0,@card_guid,@gettimes)
        set @C_number=@C_number-1
        END
    END
END

 

转载于:https://www.cnblogs.com/Thenext/p/9716686.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值