Solved

I want to modify this stored procedure to return 3 cases

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
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.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

760 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

17 Experts available now in Live!

Get 1:1 Help Now