Solved

I want to modify this stored procedure to return 3 cases

Posted on 2013-11-20
4
281 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
[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
  • 2
4 Comments
 
LVL 25

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 25

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

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

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

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 article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

752 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