生データ文字列から必要なデータを抽出するSQL関数を作成しましたが、さまざまな場所でエラーが発生し、それらを回復できません。助けてください。
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
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 @TEMP2 = @RAWDATA
IF( CHARINDEX(@TEMP3,@RAWDATA,0) = 0)
BEGIN
IF( ISNUMERIC(SUBSTRING(@RAWDATA,1,1))
BEGIN
IF((LEN(@RAWDATA) - LEN(REPLACE(@TEMP2,'/','')))>1)
BEGIN
@RAWDATA=SUBSTRING(@RAWDATA,CHARINDEX('/',@RAWDATA)+1,LEN(@RAWDATA))
@RAWDATA=SUBSTRING(@RAWDATA,CHARINDEX('/',@RAWDATA)+1,LEN(@RAWDATA))
@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))
BEGIN
SET @EMPNUM = @RAWDATA
RETURN @EMPNUM
END
ELSE
IF((SUBSTRING(@RAWDATA,1,1)='C') AND (ISNUMERIC(SUBSTRING(@RAWDATA,2,1))))
BEGIN
SET @EMPNUM = SUBSTRING(@RAWDATA,2,LEN(@RAWDATA))
RETURN @EMPNUM
END
END
END
END
END
END
そして私が直面しているエラーは
Msg 156, Level 15, State 1, Procedure Empnum, Line 11
Incorrect syntax near the keyword 'BEGIN'.
Msg 102, Level 15, State 1, Procedure Empnum, Line 15
Incorrect syntax near '@RAWDATA'.
Msg 156, Level 15, State 1, Procedure Empnum, Line 29
Incorrect syntax near the keyword 'BEGIN'.
Msg 156, Level 15, State 1, Procedure Empnum, Line 33
Incorrect syntax near the keyword 'ELSE'.
Msg 4145, Level 15, State 1, Procedure Empnum, Line 34
An expression of non-boolean type specified in a context where a condition is expected, near ')'.
Msg 156, Level 15, State 1, Procedure Empnum, Line 43
Incorrect syntax near the keyword 'END'.