Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 325
  • Last Modified:

problem with creating simple stored procedure

I have created stored procedure like below.

CREATE PROCEDURE sp_login
   @uname  varchar(20)
   @pword  varchar(20)
   
AS
Select * From tbl_login
Where username = @uname and password1=@pword
Go

Open in new window


while execution it is giving errors as

Incorrect syntax near '@pword'.

Must declare the scalar variable "@uname".

can't I declare two variables as varchar?
0
lucky20
Asked:
lucky20
2 Solutions
 
mimran18Commented:
One comma is missing only, try this...

CREATE PROCEDURE sp_login
   @uname  varchar(20),
   @pword  varchar(20)
   
AS
Select * From tbl_login
Where username = @uname and password1=@pword
Go
0
 
jogosCommented:
Off topic - naming

Try to learn naming your objects with their schema name and don't start procedures with 'sp_'. It won't break anything but it helps the db-engine to faster identify the exacte object (and you won't have the chance to have same name as a system stored procedure you didn't know about , sp_help, sp_who, sp_addlogin, sp_droplogin .....)
More info at http://blog.sqlauthority.com/2010/02/16/sql-server-stored-procedure-optimization-tips-best-practices/

CREATE PROCEDURE dbo.usp_login
   @uname  varchar(20),
   @pword  varchar(20)
   
AS
Select * 
From dbo.tbl_login
Where username = @uname and password1=@pword
Go

Open in new window

And use as
EXEC  dbo.usp_login 'John', '12ab'
0

Featured Post

Microsoft Certification Exam 74-409

VeeamĀ® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now