I have created a stored procedure to retrieve some details based on the certain values passed to a parameter. THis requires switching between the SQLs to be executed by stored procedure. Following is the code:
USE [DFS]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[DAFS]
@EmailID Nvarchar(128),
@clientID int,
@userType Varchar(50),
@Success numeric output,
@msg varchar(100) output
AS
BEGIN
if @userType='Normal User'
IF EXISTS (SELECT 1 FROM dbo.Allcdn
WHERE EmailID = @EmailID AND ClientID = @clientID)
begin
set @Success=0
set @msg='Carry on ....'
end
else
begin
set @Success=6
set @msg='Not allowed ...'
END
end
else
Begin
IF EXISTS (SELECT 1 FROM dbo.Alcon
WHERE EmailID = @EmailID AND ClientID = @clientID)
BEGIN
set @Success=0
set @msg='Carry on...'
END
END
End
end
END
The entire processing is based on the variable @userType. Not sure why the stored procedure is not compiling.
Formatting is your friend, just with a quick glance, it appears you have too many
ENDs — See SQL Fiddle with working Demo: