473,513 Members | 2,563 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Validation Store Procedure

Is There a better way I could have written the following stored procedure?
Or is my way cool?

Checking: Username, Password, Activation = True

CREATE PROCEDURE GetAuthorization
(
@Username Varchar( 20 ),
@Password Varchar( 16 )
)
AS
DECLARE @AccountID INT
SELECT @AccountID = AccountID
FROM Account
WHERE Username = @username
AND Password = @Password AND Active = 1
IF @AccountID IS NOT NULL
Return @AccountID
ELSE
IF Exists( SELECT Username
FROM Account WHERE Username = @Username)
Return - 3
ELSE
IF Exists( SELECT Username
FROM Account WHERE Username = @Username AND Password = @Password AND
Active = 0 )
Return - 2
ELSE
RETURN - 1
GO
Nov 18 '05 #1
2 1362
how about:
CREATE PROCEDURE GetAuthorization
@Username Varchar( 20 ),
@Password Varchar( 16 )
as
set nocount on
declare @AccountID int

set @AccountID = -1
select @AccountID =
case
when Password = @Password and Active = 1 then AccountID
when Password = @Password then -2
else -3
end
from Account
where Username = @Username

return @AccountID
go

actually your version would never return -2

-- bruce (sqlwork.com)

"Leon" <vn*****@msn.com> wrote in message
news:%2***************@TK2MSFTNGP09.phx.gbl...
Is There a better way I could have written the following stored procedure?
Or is my way cool?

Checking: Username, Password, Activation = True

CREATE PROCEDURE GetAuthorization
(
@Username Varchar( 20 ),
@Password Varchar( 16 )
)
AS
DECLARE @AccountID INT
SELECT @AccountID = AccountID
FROM Account
WHERE Username = @username
AND Password = @Password AND Active = 1
IF @AccountID IS NOT NULL
Return @AccountID
ELSE
IF Exists( SELECT Username
FROM Account WHERE Username = @Username)
Return - 3
ELSE
IF Exists( SELECT Username
FROM Account WHERE Username = @Username AND Password = @Password AND
Active = 0 )
Return - 2
ELSE
RETURN - 1
GO

Nov 18 '05 #2
Cool! Thanks.

"bruce barker" <no***********@safeco.com> wrote in message
news:uE**************@TK2MSFTNGP11.phx.gbl...
how about:
CREATE PROCEDURE GetAuthorization
@Username Varchar( 20 ),
@Password Varchar( 16 )
as
set nocount on
declare @AccountID int

set @AccountID = -1
select @AccountID =
case
when Password = @Password and Active = 1 then AccountID
when Password = @Password then -2
else -3
end
from Account
where Username = @Username

return @AccountID
go

actually your version would never return -2

-- bruce (sqlwork.com)

"Leon" <vn*****@msn.com> wrote in message
news:%2***************@TK2MSFTNGP09.phx.gbl...
Is There a better way I could have written the following stored
procedure?
Or is my way cool?

Checking: Username, Password, Activation = True

CREATE PROCEDURE GetAuthorization
(
@Username Varchar( 20 ),
@Password Varchar( 16 )
)
AS
DECLARE @AccountID INT
SELECT @AccountID = AccountID
FROM Account
WHERE Username = @username
AND Password = @Password AND Active = 1
IF @AccountID IS NOT NULL
Return @AccountID
ELSE
IF Exists( SELECT Username
FROM Account WHERE Username = @Username)
Return - 3
ELSE
IF Exists( SELECT Username
FROM Account WHERE Username = @Username AND Password = @Password AND
Active = 0 )
Return - 2
ELSE
RETURN - 1
GO


Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
4017
by: Jin | last post by:
Hello: I run one process that calls the following the store procedure and works fine. create PROCEDURE sp_GetHostSequenceNum AS BEGIN SELECT int_parameter_dbf + 1
4
2612
by: bnp | last post by:
Hi All, I am quite new the JavaScript. Basically I am a C++ programmer, but now I am working on JavaScript since last 5 days. I have a problem regarding the form validation. I have created a...
9
389
by: Bob | last post by:
I have a sql command with a SearchDate parameter of type date. When I execute its stored procedure from Query Analyzer (to SS2K) with a date out of the valid datetime range, EXEC @SearchDate =...
0
5673
by: jens Jensen | last post by:
Hello, I'm trying to connect to a system via https. As an additional security measure, the server requires me to attach an x509 certs to my "HTTP POST" request. I get the error...
6
2711
by: c676228 | last post by:
Hi everyone, I wrote a store procedure that fetch one row data in the database based on the parameter value I entered. After I created the store procedure, the store procedure code looks like...
0
1847
by: rxding | last post by:
Hello, Performance reason we need to move some of our code into database. Java Store Procedure is given the first choice. However, while investigating some sample code of Java store procedure, ...
0
1667
by: zhenyuandeng | last post by:
Hi, When i call the procedure sp_jysczld_new from the Query Analyzer, it runs slowly. But when i extract the sql scripts from the procedure sp_jysczld_new, it runs quickly. Why? I don't...
11
4346
by: c676228 | last post by:
Hi everyone, I am just wodering in asp program, if there is anybody writing store procedure for inserting data into database since there are so many parameters need to be passed into store...
6
3339
by: Jon Paal | last post by:
validation doesn't fire what's missing ????? /////// ---- code -----/////////////////////////// Sub btnSubmit_Click(sender As Object, e As System.Web.UI.ImageClickEventArgs) 'Handles...
0
7158
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7380
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7098
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7523
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5085
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4745
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3232
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3221
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
798
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.