Click here to Skip to main content
15,905,875 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
SQL
USE [OJTTEST]
GO
/****** Object:  StoredProcedure [dbo].[sp_getUserAccess]    Script Date: 10/16/2013 11:56:11 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		Michelle Rigor
-- Create date: 10/10/2013
-- Description:	get sp for user acess
-- =============================================
ALTER PROCEDURE [dbo].[sp_getUserAccess]
	(@UserName varchar (25),
	@Password varchar (25))
AS
DECLARE @return int
BEGIN
	SET NOCOUNT ON;
	IF (select AccessWord from UserAccess where UserName='%@UserName%' AND AccessWord ='%@Password%') = @Password 
            set @return = 1
        ELSE
            set @return = 0

END


I have this stored procedure. I want my output to be one(1) if true and zero(0) if false.
This is about the access of a user to the site if the user has access or not. Using SQL Server Management Studio 2008.
Posted

1 solution

Modify your stored procedure as follows, The below piece of code will help you...
SQL
ALTER PROCEDURE [dbo].[sp_getUserAccess]
(
	@UserName varchar (25),
	@Password varchar (25),
	@Result varchar(5) output
)
AS
BEGIN
	SET NOCOUNT ON;
	IF (select AccessWord from UserAccess where UserName='%@UserName%' AND AccessWord ='%@Password%') = @Password 
            set @Result='One'
        ELSE
            set @Result='Zero' 
END

Now, Execute the above procedure as follows:
SQL
declare @CheckUserAccess varchar(5)
Execute [dbo].[sp_getUserAccess] 'Username Here','Password Here',@result = declare @CheckUserAccess output
print @CheckUserAccess 

Example:
SQL
declare @CheckUserAccess varchar(5)
Execute [dbo].[sp_getUserAccess] 'Dipesh','121',@result = declare @CheckUserAccess output
print @CheckUserAccess 

The above example will print ONE if username and password EXIST in table.
The above example will print ZERO if username and password DOES NOT EXIST in Table.
 
Share this answer
 
Comments
mitchiee1226 16-Oct-13 3:26am    
how come when I execute the procedure it outputs "zero" always even though the username and password exist?
Dipesh Wadhwa 16-Oct-13 6:36am    
Modify if Condition as follows

IF (select AccessWord from UserAccess where UserName=@username AND AccessWord=@password) = @Password

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900