Getting error in SQL server stored procedure when executing it:
USE [ConsumerBanking]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[GetCBLoginInfo]
@UserName VARCHAR(20),
@Password varchar(20)
AS
SET NOCOUNT ON
Declare @Failedcount AS INT
SET @Failedcount = (SELECT LoginFailedCount from CBLoginInfo WHERE UserName = @UserName)
IF EXISTS(SELECT * FROM CBLoginInfo WHERE UserName = @UserName)
BEGIN
IF EXISTS(SELECT * FROM CBLoginInfo WHERE UserName = @UserName AND Password = @Password )
SELECT 'Success' AS UserExists
ELSE
Update CBLoginInfo set LoginFailedCount = @Failedcount+1 WHERE UserName = @UserName
Update CBLoginInfo set LastLoginDate=GETDATE() WHERE UserName = @UserName
BEGIN
IF @Failedcount >=5
SELECT 'Maximum Attempt Reached (5 times) .Your Account is locked now.' AS UserExists
ELSE
select CONVERT(varchar(10), (SELECT LoginFailedCount from CBLoginInfo WHERE UserName = @UserName)) AS UserFailedcount
END
END
ELSE
BEGIN
SELECT 'User Does not Exists' AS UserExists
END
It is diificult to understand what is the error and what are you trying to do, looking at procedure only.
If you are new to stored procedure and still learning about SQL server stored procedures, please check this article:
https://qawithexperts.com/article/sql/stored-procedure-in-sql-server-with-example/203
Also, please explain your question in detail, it should contain every detail like "what are your trying to do? what end result you expect? sql table on which you are running stored procedure?" so we can understand and solve your query accordingly, if possible.
Subscribe to our weekly Newsletter & Keep getting latest article/questions in your inbox weekly