Solved

problem with creating simple stored procedure

Posted on 2012-03-14
2
320 Views
Last Modified: 2012-03-14
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
Comment
Question by:lucky20
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 9

Accepted Solution

by:
mimran18 earned 250 total points
ID: 37723401
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
 
LVL 25

Assisted Solution

by:jogos
jogos earned 250 total points
ID: 37723444
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Via a live example, show how to shrink a transaction log file down to a reasonable size.

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question