Solved

I want to modify this stored procedure to return 3 cases

Posted on 2013-11-20
4
275 Views
Last Modified: 2013-11-21
if username and password is ok and isemailapproved is false  - "LogOKeMailnotOK"

if username and password is not ok then  - "LogFailed"

if username and password is ok and isemailapproved is true  - "OK"


USE [rightmatch]
GO



/****** Object:  StoredProcedure [dbo].[pVerifyCredentials]    Script Date: 11/20/2013 18:46:14 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER PROCEDURE [dbo].[pVerifyCredentials](
      @UserName VARCHAR(20),
      @Algorithm VARCHAR(16),
      @Pass VARCHAR(16)
)
AS
BEGIN
      set nocount on
      select case num when 1 then 'OK'
                      else 'Failed'
                      end as Result
        from (
      SELECT count(*) as Num
        FROM Members
       WHERE MemberName = @UserName
         AND Password = HASHBYTES(@Algorithm, @Pass)
         AND IsEmailApproved=1
              ) AS X
END
return
0
Comment
Question by:goodk
  • 2
  • 2
4 Comments
 
LVL 24

Expert Comment

by:chaau
ID: 39664624
You can adjust the statement like this:
 select case when num = 1 AND email <> 1 then 'LogOKeMailnotOK'
              when num = 1 AND email = 1 then 'OK'
                      else 'LogFailed'
                      end as Result
        from (
      SELECT count(*) as Num,
                   max(IsEmailApproved) as email
        FROM Members
       WHERE MemberName = @UserName
         AND Password = HASHBYTES(@Algorithm, @Pass)
              ) AS X

Open in new window

0
 

Author Comment

by:goodk
ID: 39664931
Msg 8117, Level 16, State 1, Procedure pPWEmailVerify, Line 16
Operand data type bit is invalid for max operator.
0
 
LVL 24

Accepted Solution

by:
chaau earned 500 total points
ID: 39664949
OK then, change it to this:
 select case when num = 1 AND email <> 1 then 'LogOKeMailnotOK'
              when num = 1 AND email = 1 then 'OK'
                      else 'LogFailed'
                      end as Result
        from (
      SELECT count(*) as Num,
                   max(CASE When IsEmailApproved=1 THEN 1 ELSE 0 END) as email
        FROM Members
       WHERE MemberName = @UserName
         AND Password = HASHBYTES(@Algorithm, @Pass)
              ) AS X

Open in new window

0
 

Author Closing Comment

by:goodk
ID: 39666073
thanks,

What if I want to do two separate sqls and want different returns. Can you guide me where can I read up on how to do the stored procedures.  Thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PL/SQL LOOP CURSOR 3 56
Help writing a query 6 70
subtract 1 in Access 2003 query 7 36
Getting same value for every field in SQL 2 10
Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

929 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now