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
 Transact-SQL (2000)
 How to correctly nest if statements

Author  Topic 

erikkl2003
Starting Member

14 Posts

Posted - 2005-12-09 : 20:58:37
in sql2000?

Hello all,

i can not seem to find the correct way to nest these if statements..
i am tring to get a little better understanding of handeling messaging the client... on updates and inserts..

thanks in advance for the help!
erik.
============================================

Server: Msg 156, Level 15, State 1, Procedure Admin_Compare_Email_w_UserID, Line 28
Incorrect syntax near the keyword 'ELSE'.
Server: Msg 170, Level 15, State 1, Procedure Admin_Compare_Email_w_UserID, Line 32
Line 32: Incorrect syntax near 'END'.

================================================


SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

ALTER PROCEDURE Admin_Compare_Email_w_UserID


@Admin_Email Varchar (200), /*Admin Check */

@UserID int,
@UserType Varchar (30),
@LastName Varchar (30),
@Email Varchar (200)

As

DECLARE @err Varchar (30)

IF EXISTS (SELECT Email, FirstName, UserType FROM Users WHERE Email = @Admin_Email AND UserType = 'Admin')
BEGIN
IF EXISTS (SELECT FirstName FROM Users WHERE UserID = UserID AND Email = Email)
BEGIN
SET @err = 'Users Credentials Match!'
SELECT @err as lblerror
END
ELSE
BEGIN
SET @err = 'Users Credentials do not Match!'
SELECT @err as lblerror
END
ELSE
BEGIN
SET @err = 'Admin Credentials do not Match!'
SELECT @err as lblerror
END

GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO



If you wait untill tomorrow; you will have no future.

erikkl2003
Starting Member

14 Posts

Posted - 2005-12-09 : 21:13:04
bEEN Up way to long,,, for got to add the @ to my where clause


UserID = @UserID AND Email = @Email

If you wait untill tomorrow; you will have no future.
Go to Top of Page

azmi
Starting Member

37 Posts

Posted - 2005-12-09 : 21:28:54
you are repeating the else statement in your if statement. Try this;

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

ALTER PROCEDURE Admin_Compare_Email_w_UserID

@Admin_Email Varchar (200), /*Admin Check */
@UserID int,
@UserType Varchar (30),
@LastName Varchar (30),
@Email Varchar (200)

As

DECLARE @err Varchar (30)

IF EXISTS (SELECT Email, FirstName, UserType FROM Users WHERE Email = @Admin_Email AND UserType = 'Admin')

BEGIN
IF EXISTS (SELECT FirstName FROM Users WHERE UserID = UserID AND Email = Email)
BEGIN
SET @err = 'Users Credentials Match!'
SELECT @err as lblerror
END

ELSE
BEGIN
SET @err = 'Users Credentials do not Match!'
SELECT @err as lblerror
END

END

GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

I had compiled sucessfully. Hope it's help u...
Go to Top of Page

erikkl2003
Starting Member

14 Posts

Posted - 2005-12-09 : 21:33:38
Thank you very much for the reply!!
erik...

and the help..

If you wait untill tomorrow; you will have no future.
Go to Top of Page
   

- Advertisement -