我之前已经在下面发布了编写的代码,并得到了正确的代码并消除了错误,但我的标准不令人满意,下面是作为参数传递的原始数据
2007:10113:/I/69071/MLI/Eldridge
作为回报,输出应该是“69071”,为此我给出了以下函数,但我没有得到输出,而且我还保留了一些其他条件来满足其他要求,请帮助我。
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON --2007:10113:/I/69071/MLI/Eldridge
go
ALTER FUNCTION [dbo].[Empnum] (@RAWDATA NVARCHAR(300))
RETURNS VARCHAR(30)
AS
BEGIN
DECLARE @TEMP1 NVARCHAR(300), @EMPNUM NVARCHAR(10), @TEMP2 NVARCHAR(300), @TEMP3 NVARCHAR(300)
SET @TEMP3 = 'Disabled'
SET @EMPNUM=''
SET @TEMP2 = @RAWDATA
IF( CHARINDEX(@TEMP3,@RAWDATA,1) = 0)
BEGIN
-- SET @EMPNUM='11'
IF ISNUMERIC(SUBSTRING(@RAWDATA,1,1)) = 1
BEGIN
--
IF((LEN(@RAWDATA) - LEN(REPLACE(@TEMP2,'/','')))>1)
BEGIN
SET @RAWDATA=SUBSTRING(@RAWDATA,CHARINDEX('/',@RAWDATA)+1,LEN(@RAWDATA))
SET @RAWDATA=SUBSTRING(@RAWDATA,CHARINDEX('/',@RAWDATA)+1,LEN(@RAWDATA))
SET @RAWDATA=SUBSTRING(@RAWDATA,1,CHARINDEX('/',@RAWDATA)-1)
IF( CHARINDEX('*C',@RAWDATA) = 0 OR
CHARINDEX('CV',@RAWDATA) = 0 OR
CHARINDEX('AV',@RAWDATA) = 0 OR
CHARINDEX('LV',@RAWDATA) = 0 )
BEGIN
SET @EMPNUM = ''
RETURN @EMPNUM
END
ELSE
BEGIN
IF ISNUMERIC(SUBSTRING(@RAWDATA,1,1)) = 1
BEGIN
SET @EMPNUM = @RAWDATA
RETURN @EMPNUM
END
ELSE
IF((SUBSTRING(@RAWDATA,1,1)='C') AND ISNUMERIC(SUBSTRING(@RAWDATA,2,1)) = 1)
BEGIN
SET @EMPNUM = SUBSTRING(@RAWDATA,2,LEN(@RAWDATA))
RETURN @EMPNUM
END
END
END
END
END
RETURN @EMPNUM
END