Solved

I want to modify this stored procedure to return 3 cases

Posted on 2013-11-20
4
280 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
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.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

749 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