我想在 MSSQL Server 2008 中生成一个 ID。它将是前缀 + 数字 + 后缀,如“PV#000001#SV”。这将是用户定义的(取决于配置)前缀、数字长度、后缀和起始编号。数字每次都会增加。
我绑写这个:
Blockquote ALTER PROCEDURE [dbo].[spACC_SELECT_VOUCHER_NUMBER]
@COMPANY_ID uniqueidentifier, @VOUCHER_TYPE INT
开始
DECLARE @IS_AUTOMETIC BIT =(从 ACC_VOUCHER_CONFIG 中选择 VOUCHER_CONFIG_NUMBERING_METHOD,其中 ACC_VOUCHER_CONFIG.VOUCHER_CONFIG_VALUE=@VOUCHER_TYPE)
IF(@IS_AUTOMETIC=1) BEGIN SELECT CASE WHEN SUBSTRING(V.VOUCHER_CODE, 7, 23) IS NULL THEN CASE WHEN VC.VOUCHER_CONFIG_PREFIX IS NULL THEN '' ELSE VC.VOUCHER_CONFIG_PREFIX END + RIGHT ('0000000000000'+ CAST( VC.VOUCHER_CONFIG_BEGINING_NUMBER AS VARCHAR), VC.VOUCHER_CONFIG_NUMERIC_WIDTH) + CASE WHEN VC.VOUCHER_CONFIG_SUFFIX IS NULL THEN '' ELSE VC.VOUCHER_CONFIG_SUFFIX END ELSE CASE WHEN VC.VOUCHER_CONFIG_PREFIX IS NULL THEN '' ELSE VC.VOUCHER_CONFIG_PREFIX END + RIGHT ('0000000000000'+ CAST((CAST( SUBSTRING(V.VOUCHER_CODE, 7, 23) AS INT)+1) AS VARCHAR), VC.VOUCHER_CONFIG_NUMERIC_WIDTH) + CASE WHEN VC.VOUCHER_CONFIG_SUFFIX IS NULL THEN '' ELSE VC.VOUCHER_CONFIG_SUFFIX END END AS VOUCHER_CODE FROM ACC_VOUCHER_CONFIG VC LEFT OUTER JOIN ACC_VOUCHER V ON VC.VOUCHER_CONFIG_VALUE = V.VOUCHER_TYPE WHERE VC.COMPANY_ID=@COMPANY_ID AND VC.VOUCHER_CONFIG_VALUE=@VOUCHER_TYPE END
结尾
当我更改数字长度/后缀时,它不起作用。
谢谢纳希德
_