我最终让它做我需要做的事情:
create PROCEDURE [dbo].[spv_parseGLAccounts] (
@AllowableAccountFilter AS varchar(250),
@DeptID AS varchar(6),
@CompCode AS varchar(6)) AS
BEGIN
SET NOCOUNT ON;
DECLARE @FirstOrLocation int, @FirstRangeLocation int;
DECLARE @LeftPart varchar(250), @RightPart varchar(250)
SET @AllowableAccountFilter = LTRIM(RTRIM(@AllowableAccountFilter))
SET @FirstOrLocation = CHARINDEX('|',@AllowableAccountFilter)
SET @FirstRangeLocation = CHARINDEX('.',@AllowableAccountFilter)
IF @FirstOrLocation <> 0 -- Split on |
BEGIN
SET @LeftPart = SUBSTRING(@AllowableAccountFilter, 1, @FirstOrLocation - 1)
SET @RightPart = SUBSTRING(@AllowableAccountFilter, @FirstOrLocation + 1, LEN(@AllowableAccountFilter) - @FirstOrLocation)
EXEC spv_parseGLAccounts @LeftPart, @DeptID, @CompCode
EXEC spv_parseGLAccounts @RightPart, @DeptID, @CompCode
END
ELSE IF @FirstRangeLocation <> 0 -- Split on ..
BEGIN
INSERT INTO ValidAccountMapping (DeptID, CompCode, BeginAccount, EndAccount)
VALUES (@DeptID, @CompCode, SUBSTRING(@AllowableAccountFilter, 1, @FirstRangeLocation - 1),
SUBSTRING(@AllowableAccountFIlter, @FirstRangeLocation + 2, LEN(@AllowableAccountFilter) - @FirstRangeLocation - 1))
END
ELSE
BEGIN
INSERT INTO ValidAccountMapping (DeptID, CompCode, BeginAccount, EndAccount)
VALUES (@DeptID, @CompCode, @AllowableAccountFilter, @AllowableAccountFilter)
END
END