Tsql scalar valued function syntax not working

Hi Experts

Gettting these error messages when running the, please help

Msg 102, Level 15, State 1, Procedure psCPTY_CODE_TYPE, Line 23
Incorrect syntax near '@Cpty_Code_Type'.
Msg 156, Level 15, State 1, Procedure psCPTY_CODE_TYPE, Line 25
Incorrect syntax near the keyword 'ELSE'.
CREATE FUNCTION psCPTY_CODE_TYPE
(
	@Cpty_Code_Type Nvarchar(10),
	@TradCond Nvarchar(10)	
)
RETURNS  nvarchar(1)
AS
BEGIN

declare @return nvarchar(1)

	IF upper(@TradCond) ='AGY'
		SET @Return = 'I'
	ELSE
		BEGIN
			 IF @Cpty_Code_Type = 'BIC' 
				SET @Return = 'B'
			 ELSE @Cpty_Code_Type = 'SIB' 
				SET @Return = 'R'
			 ELSE
				SET @Return ='I'	
		END
	
	RETURN @return 
END

Open in new window

MrDavidThornAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Philip PinnellConnect With a Mentor Commented:
CREATE FUNCTION psCPTY_CODE_TYPE
(
      @Cpty_Code_Type Nvarchar(10),
      @TradCond Nvarchar(10)      
)
RETURNS  nvarchar(1)
AS
BEGIN

declare @return nvarchar(1)

      IF upper(@TradCond) ='AGY'
            SET @Return = 'I'
      ELSE
            BEGIN
                   IF @Cpty_Code_Type = 'BIC'
                        SET @Return = 'B'
                   ELSE IF @Cpty_Code_Type = 'SIB'
                        SET @Return = 'R'
                   ELSE
                        SET @Return ='I'      
            END
      
      RETURN @return
END


missed an IF
0
 
MrDavidThornAuthor Commented:
thanks dude
0
 
Philip PinnellCommented:
No problem. Easily missed
0
All Courses

From novice to tech pro — start learning today.