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