标签:creat int sed roc convert machine number drop mac
DROP PROCEDURE CreateNextSerialNumber GO
CREATE PROCEDURE CreateNextSerialNumber @SerialNumberPrefix VARCHAR(2), @NextSerialNumber VARCHAR(10) OUT AS BEGIN DECLARE @MaxSerialNumber VARCHAR(10), @CurrentNumber VARCHAR(8), @NextNumber VARCHAR(8), @PrefixNumber VARCHAR(2) BEGIN SELECT @MaxSerialNumber = MAX(HIMPSerialNumber) FROM ClientMachineInfo IF LEN(@SerialNumberPrefix) != 2 SET @PrefixNumber = ‘SN‘ ELSE SET @PrefixNumber = @SerialNumberPrefix IF ISNULL(@MaxSerialNumber, ‘‘) = ‘‘ BEGIN SET @NextNumber = ‘00000000‘ END ELSE BEGIN SET @CurrentNumber = RIGHT(@MaxSerialNumber, LEN(@PrefixNumber)) SET @NextNumber = RIGHT(‘00000000‘ + CONVERT(VARCHAR(8), CAST(@CurrentNumber AS INT) + 1), 8) END SET @NextSerialNumber = @PrefixNumber + @NextNumber INSERT INTO ClientMachineInfo(HIMPSerialNumber, Used) VALUES(@NextSerialNumber, 1) END END GO
标签:creat int sed roc convert machine number drop mac
原文地址:http://www.cnblogs.com/wxs121/p/6768173.html