如何检测我@AE_LedgerAC
的存储过程中的参数仅包含 6 个字符?如果它只包含 6 个字符,我想在前面添加此表中包含的详细信息BIN.BranchId
:
ALTER PROCEDURE [dbo].[AccountEntries]
@AE_LedgerAC varchar(21)=null,
@AE_Transaction_Ref varchar(50)=null,
@AE_Detail nvarchar(50)=null,
AS
DECLARE @NEW_LedgerAC varchar(21) = null
IF(LEN(@AE_LedgerAC) = 6)
BEGIN
@NEW_LedgerAC = SELECT TOP 1 BIN.BranchId FROM BIN + @AE_LedgerAC
ELSE
@NEW_LedgerAC = @AE_LedgerAC
INSERT INTO [AccountEntries](LedgerAC, Transaction_Ref, Detail)
VALUES (@AE_LedgerAC, @AE_Transaction_Ref, @AE_Detail)