Question

Before I added the case statements, I was not receiving an error. I needed to add the case statements to supply the home phone number as a backup if the H1 or H2 cell phone fields are blank or null (best way I know how to do it, as a novice). For some reason I am getting a Syntax Error (missing operator) in query expression. It notes the error for both case statements. As far as I can tell, they are written correctly... anyone know what's up? Thanks.

SELECT [H1 Last Name] & ", " & [H1 First Name] as [Full Name],[H1 E-Mail]
CASE
     WHEN [H1 Cell Phone] IS NULL
     THEN [Home Phone]
     ELSE [H1 Cell Phone] END as [Phone]

FROM NameLookup 
WHERE (((NameLookup.[H1 Last Name]) NOT LIKE '%SPEC%') OR ((NameLookup.[H1 Last Name]) NOT LIKE '%MODEL%')) AND ((NameLookup.[H1 Last Name]) IS NOT NULL)

UNION

SELECT [H2 Last Name] & ", " & [H2 First Name] as [Full Name],[H2 E-Mail]
CASE
     WHEN [H2 Cell Phone] IS NULL
     THEN [Home Phone]
     ELSE [H2 Cell Phone] END as [Phone]

FROM NameLookup 
WHERE (((NameLookup.[H1 Last Name]) NOT LIKE '%SPEC%') OR ((NameLookup.[H1 Last Name]) NOT LIKE '%MODEL%')) AND ((NameLookup.[H1 Last Name]) IS NOT NULL)


Order By 1;
Was it helpful?

Solution

Are you using that in MS Access ACE? Case is not available, use IIF(argument, true value, false value)

SELECT [H1 Last Name] & ", " & [H1 First Name] as [Full Name],[H1 E-Mail],
IIF ( [H1 Cell Phone] IS NULL, [Home Phone], [H1 Cell Phone] ) AS Phone
FROM NameLookup 

Access SQL Functions: http://www.techonthenet.com/access/functions/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top