Avatar of Harreni
Harreni
Flag for Saudi Arabia

asked on 

What is wrong with this Stored Procedure

HI Experts,

I have IF and ELSE statements and keep getting this error:
Msg 156, Level 15, State 1, Procedure TEST, Line 29
Incorrect syntax near the keyword 'ELSE'.


Here is my code:
ALTER PROCEDURE TEST
@ConsumerID nvarchar(50) 
AS
BEGIN
SET NOCOUNT ON;
DECLARE @Description NVARCHAR (255)=NULL;

SELECT C.ConsumerName
FROM Consumers C
WHERE C.ConsumerID = N'A1'
IF @@ROWCOUNT>0
	BEGIN
	PRINT'Founded'
END

	IF
	((SELECT C.ConsumerID
	FROM Consumers C
	WHERE C.ConsumerID = N'A1')= N'No')
	BEGIN
		SET @Description = N'Not ON GSB';
	END

	ELSE
	BEGIN
		SET @Description = N'YES ON GSB';
	END
	
ELSE
BEGIN
	PRINT N'Not Found'
END

END

Open in new window


Please correct me if I write it in a wrong way.

Thanks a lot in advance,
Harreni
Microsoft SQL ServerSQL

Avatar of undefined
Last Comment
Lee

8/22/2022 - Mon