Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

I want to modify this stored procedure to return 3 cases

Posted on 2013-11-20
4
Medium Priority
?
285 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 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 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

In database programming, custom sort order seems to be necessary quite often, at least in my experience and time here at EE. Within the realm of custom sorting is the sorting of numbers and text independently (i.e., treating the numbers as number…
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…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses
Course of the Month7 days, 15 hours left to enroll

824 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