Iamthestig
Programmer
Can someone please help me with this?
DECLARE @REF int
DECLARE @PreferredEmail as varchar(50)
SET @REF = 102108
SET @PreferredEmail = IF (SELECT WorkEmailPreferred FROM tblContactPersonal WHERE CREF = @REF) =1
BEGIN
SELECT Email FROM tblContactPersonal WHERE CREF = @REF
END
ELSE
IF (SELECT PrivateEmailPreferred FROM tblContactPersonal WHERE CREF = @REF) = 1
BEGIN
SELECT PrivateEmail FROM tblContactPersonal WHERE CREF = @REF
END
ELSE
IF (SELECT Email FROM tblContactPersonal WHERE CREF = @REF) <> ''
BEGIN
SELECT Email FROM tblContactPersonal WHERE CREF = @REF
END
ELSE
IF (SELECT PrivateEmail FROM tblContactPersonal WHERE CREF = @REF) <> ''
BEGIN
SELECT PrivateEmail FROM tblContactPersonal WHERE CREF = @REF
END
I get an 'Incorrect syntax near the keyword 'IF' error.
DECLARE @REF int
DECLARE @PreferredEmail as varchar(50)
SET @REF = 102108
SET @PreferredEmail = IF (SELECT WorkEmailPreferred FROM tblContactPersonal WHERE CREF = @REF) =1
BEGIN
SELECT Email FROM tblContactPersonal WHERE CREF = @REF
END
ELSE
IF (SELECT PrivateEmailPreferred FROM tblContactPersonal WHERE CREF = @REF) = 1
BEGIN
SELECT PrivateEmail FROM tblContactPersonal WHERE CREF = @REF
END
ELSE
IF (SELECT Email FROM tblContactPersonal WHERE CREF = @REF) <> ''
BEGIN
SELECT Email FROM tblContactPersonal WHERE CREF = @REF
END
ELSE
IF (SELECT PrivateEmail FROM tblContactPersonal WHERE CREF = @REF) <> ''
BEGIN
SELECT PrivateEmail FROM tblContactPersonal WHERE CREF = @REF
END
I get an 'Incorrect syntax near the keyword 'IF' error.