Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 ASP to check for existing members

Author  Topic 

mberger
Starting Member

2 Posts

Posted - 2002-03-02 : 16:04:22
I have very little SQL experience. I need to check two fields in a table to see if any email addresses match one that someone is trying to register with in a Snitz forum. If there is a match, I will register the member - if not, I will return a message telling them they are not eligible.

How would I do this?

Mike

aiken
Aged Yak Warrior

525 Posts

Posted - 2002-03-02 : 16:29:45

CREATE FUNCTION f_EmailExists (@vcEmail varchar(100))
RETURNS tinyint AS
BEGIN
DECLARE @tiResult TINYINT

IF EXISTS (SELECT * FROM USERS WHERE FIELD1=@vcEMAIL) OR EXISTS (SELECT * FROM USERS WHERE FIELD2=@vcEMAIL)
SET @tiResult=1
ELSE
SET @tiResult=0

RETURN @tiResult
END


In your ASP page:

szSQL="select dbo.f_EmailExists('" & szEmail & "') as valid"
' (open the recordset, however you choose to do that)
iEmailValid=CInt(RS("valid"))


Be sure to set permissions on the function so the user your ASP page is logging in as can run it.

Alternatively, you could use a stored procedure, with almost identical code. I'd use a function here because it's possible you'd want to use the function in another query later.

Cheers
-b


Go to Top of Page

mberger
Starting Member

2 Posts

Posted - 2002-03-02 : 18:36:32
Exactly what I was looking for. Thanks, I really appreicate it. I'll give it a try.

Mike

Go to Top of Page
   

- Advertisement -