stored proc to check multiple column values

Posted by Parthibansk under Sql Server on 11/1/2012 | Points: 10 | Views : 1315 | Status : [Member] | Replies : 1
i wrote a sp to check if user exists or not.. is it possible to check multiple colum values in a single stored procedure.
need to check username as well as companyname..

here is my sp:

USE [EMPLOYEE]
GO
/****** Object: StoredProcedure [dbo].[checkuserinf] Script Date: 11/01/2012 16:57:31 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER proc [dbo].[checkuserinf]
@username varchar(50),@email varchar(50),@password varchar(50),@error varchar
(100) out

as

begin

-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.

SET NOCOUNT ON;

---Checking Condition if User exists or not if user not exists returns different message if exists returns different message
if not exists(select * from registration where email=@email)

begin

insert into registration
(username,email,password) values (@username,@email,@password)

--If User Successfully Registerd I am returing this Message as Output Parameter

SET @ERROR= @email +' Registered Successfully'
END
ELSE
BEGIN
--If User already Exists i am returning this Message as Output Parameter
SET @ERROR=@email + ' Already Exists'
END
END




Responses

Posted by: Vivekjj on: 11/2/2012 [Member] Starter | Points: 25

Up
0
Down
Ya its possible otherwise you can use joins in ur query
for example
if not exists(select * from registration r left join company c on r.regno=c.no where email=@email)

or

try this

SET NOCOUNT ON;
---Checking Condition if User exists or not if user not exists returns different message if exists returns different message
if not exists(select * from registration where email=@email)
if @@Rowcount>0
if not exists(select * from company where email=@email)
begin

insert into registration
(username,email,password) values (@username,@email,@password)


Parthibansk, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response