3
Answers

How to solve this error?

selva kumar

selva kumar

10y
1.1k
1
Hi i have created stored procedure for user login but it throws error..can any one help me out..

Create Table Tbl_Login(T_Id Int Identity(1,1),Mode Varchar(50),UserName Varchar(50),[PassWord] Varchar(50));

Select * From Tbl_Login;

Truncate Table Tbl_Login;

Drop Table Tbl_Login;

/*Stored procedure for User_Login*/

Create Proc SP_Login(@Mode Varchar(50),@Name Varchar(50),@PassWord Varchar(50,@Res INTEGER Output)
as
if exists(Select Mode,UserName,[PassWord] From Tbl_Login Where Mode=@Mode and UserName=@Name and [PassWord]=@PassWord)
set @Res=1
else
set @Res=0
go
Exec Proc SP_Login


Error:

Msg 102, Level 15, State 1, Procedure SP_Login, Line 1
Incorrect syntax near '@Res'.
Msg 137, Level 15, State 2, Procedure SP_Login, Line 3
Must declare the scalar variable "@PassWord".
Msg 137, Level 15, State 1, Procedure SP_Login, Line 4
Must declare the scalar variable "@Res".
Msg 137, Level 15, State 1, Procedure SP_Login, Line 6
Must declare the scalar variable "@Res".
Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'Proc'.

Answers (3)
1
Jignesh Trivedi

Jignesh Trivedi

NA 61k 14.2m 10y
hi,

Agree with Anupam Singh, you forgot the close braces before @res variable.
1
Ranjit Powar

Ranjit Powar

NA 8.1k 496.5k 10y
Closing bracket is missing correct it.

Create Proc SP_Login(@Mode Varchar(50),@Name Varchar(50),@PassWord Varchar(50),@Res INTEGER Output)
1
Anupam Singh

Anupam Singh

NA 5.8k 886.9k 10y
Hi selva,,

Try this :
Create Proc SP_Login(@Mode Varchar(50),@Name Varchar(50),@PassWord Varchar(50),@Res INTEGER Output)
as 
if exists(Select Mode,UserName,[PassWord] From Tbl_Login Where Mode=@Mode and UserName=@Name and [PassWord]=@PassWord)
set @Res=1
else 
set @Res=0
go

I have highlighted where you were wrong.