jacktripper
Programmer
I am a completely average query programmer. I built a simple SPROC so a user can retrieve their password from the system based on 3 criteria. The SELECT query either finds a match for all 3 in the WHERE clause, or it fails.
The 3 criteria are e-mail, birthdate, and zipcode.
But, I'd like to be able to tell the user what part of the SELECT failed. For example, "The e-mail could not be found in the system". Or, if the e-mail IS found, but the zipcode doesn't match... then be able to say that to them.
I started to build a sproc to do this, but its not going well. I figure there must be an easier way??? Either that or my If/Else is just stupid, because I get a blank result from the ELSE section if I have a matching E-mail.
What I started with is:
SELECT @FoundEmail = Employee.Email
FROM Employee
WHERE (Employee.Email=@Email)
If @FoundEmail = ''
Set @ReturnMessage = 'That E-mail was not found in our system'
Else
SELECT @FoundZip = Employee.Zipcode
FROM Employee WHERE Employee.Email = @Email
If @FoundZip = '' and @FoundEmail <> ''
Set @ReturnMessage = 'e-mail found but cannot find zipcode'
END
Any thoughts?
The 3 criteria are e-mail, birthdate, and zipcode.
But, I'd like to be able to tell the user what part of the SELECT failed. For example, "The e-mail could not be found in the system". Or, if the e-mail IS found, but the zipcode doesn't match... then be able to say that to them.
I started to build a sproc to do this, but its not going well. I figure there must be an easier way??? Either that or my If/Else is just stupid, because I get a blank result from the ELSE section if I have a matching E-mail.
What I started with is:
SELECT @FoundEmail = Employee.Email
FROM Employee
WHERE (Employee.Email=@Email)
If @FoundEmail = ''
Set @ReturnMessage = 'That E-mail was not found in our system'
Else
SELECT @FoundZip = Employee.Zipcode
FROM Employee WHERE Employee.Email = @Email
If @FoundZip = '' and @FoundEmail <> ''
Set @ReturnMessage = 'e-mail found but cannot find zipcode'
END
Any thoughts?