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

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

时间:2018-09-28 10:59:28      阅读:118      评论:0      收藏:0      [点我收藏+]

标签:pre   for   tom   服务   declare   else   col   convert   int   

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

 

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

标签:pre   for   tom   服务   declare   else   col   convert   int   

原文地址:https://www.cnblogs.com/Thenext/p/9716686.html

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