Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

problem with creating simple stored procedure

Posted on 2012-03-14
2
Medium Priority
?
323 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 1000 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 1000 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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
When trying to connect from SSMS v17.x to a SQL Server Integration Services 2016 instance or previous version, you get the error “Connecting to the Integration Services service on the computer failed with the following error: 'The specified service …
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

670 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