Solved

problem with creating simple stored procedure

Posted on 2012-03-14
2
321 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
I have a large data set and a SSIS package. How can I load this file in multi threading?
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

615 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