我爲我的Primarykey列生成一個字符串類似的標識函數。但其行爲是意想不到的。 它通過字符串去除全部0並僅存儲單個字符。糾正我我在哪裏錯了..通過UDFunction生成唯一字符串
Alter FUNCTION [dbo].[UDF_GenerateBatchNumber] (@BatchNumber as Varchar(10))
Returns Varchar
AS
BEGIN
-- Declare the return variable here
-- Add the T-SQL statements to compute the return value here
Select Top(1) @BatchNumber=[BatchNo] From TBL_iBATCH Order by [BatchNo] desc
IF @BatchNumber is Null
BEGIN
Set @BatchNumber ='B000001'
END
Else
BEGIN
Set @BatchNumber='B'+Convert(Varchar(7),(Cast(SUBSTRING(@BatchNumber,2,7) as Integer)+1))
END
RETURN @BatchNumber
END
你不想去2,6?而不是2,7?長度是7與b 6沒有 – xQbert 2011-12-19 12:25:10
爲什麼它刪除領導0的 – joshua 2011-12-19 12:33:25