Link to home
Start Free TrialLog in
Avatar of Debra Turner
Debra TurnerFlag for United States of America

asked on

SQL error: "expression of non-boolean type specified in a context where a condition is expected, near 'WHERE'"

I had this question after viewing Need Distinct Value from Joined Tables in MSSQL.

With this SQL query, I am trying to match the faculty members with their topics. The user is presented with a dropdown of Research Topics, When selected, the user should be presented with a list of faculty members who are working in research on those topics.

My Query:

SELECT First_Name, Last_Name, Department_Name, suapp.FACULTY.Faculty_UUID, Faculty_Email, Faculty_Title, Faculty_Profile_Link FROM suapp.FACULTY            
JOIN (SELECT DISTINCT
suapp.RESEARCH_MATCH.Faculty_UUID
FROM suapp.RESEARCH_MATCH
JOIN suapp.AREA_TOPIC.Area_Topic_Code
ON suapp.RESEARCH_MATCH.Area_Topic_Code
WHERE suapp.RESEARCH_MATCH.Area_Topic_Code = suapp.AREA_TOPIC.Area_Topic_Code
AND suapp.AREA_TOPIC.Area_Topic_Code = 'CD-a'
) rm ON suapp.FACULTY.Faculty_UUID = rm.Faculty_UUID ORDER BY suapp.FACULTY.Last_Name, suapp.FACULTY.First_Name;

The error:
An expression of non-boolean type specified in a context where a condition is expected, near 'WHERE'.

suapp-research-dashboard-example-deb.pdf
Thank you for any help in this situation.
Debra Turner
Avatar of ste5an
ste5an
Flag of Germany image

First of all, please use the embed CODE button..

The issue is a copy'n'paste error. You have simply a WHERE where none is needed. E.g.

SELECT  First_Name ,
        Last_Name ,
        Department_Name ,
        suapp.FACULTY.Faculty_UUID ,
        Faculty_Email ,
        Faculty_Title ,
        Faculty_Profile_Link
FROM    suapp.FACULTY
        JOIN ( SELECT DISTINCT
                        suapp.RESEARCH_MATCH.Faculty_UUID
               FROM     suapp.RESEARCH_MATCH
                        JOIN suapp.AREA_TOPIC.Area_Topic_Code ON suapp.RESEARCH_MATCH.Area_Topic_Code = suapp.AREA_TOPIC.Area_Topic_Code
                                                                 AND suapp.AREA_TOPIC.Area_Topic_Code = 'CD-a'
             ) rm ON suapp.FACULTY.Faculty_UUID = rm.Faculty_UUID
ORDER BY suapp.FACULTY.Last_Name ,
        suapp.FACULTY.First_Name;

Open in new window


btw, please use table alias names and qualify all used column names with it.
I think the JOIN ... ON needs to have some kind of equality expression in the ON clause.  This is just a guess, but maybe something along these lines:

JOIN suapp.AREA_TOPIC.Area_Topic_Code
ON suapp.RESEARCH_MATCH.Area_Topic_Code = suapp.AREA_TOPIC.Area_Topic_Code
Avatar of Debra Turner

ASKER

Dear Stefan,
Thank you for your quick response. I am getting new errors with these changes.

Invalid object name 'suapp.AREA_TOPIC.Area_Topic_Code'

And I'm not sure what you mean by:
"btw, please use table alias names and qualify all used column names with it"
Thank you for your help.
debra
Dear Ray,

I changed my query to reflect your example and am now getting a new error.
Error
Msg 208, Level 16, State 1, Line 1
Invalid object name 'suapp.AREA_TOPIC.Area_Topic_Code'.

SELECT First_Name, Last_Name, Department_Name, suapp.FACULTY.Faculty_UUID, Faculty_Email, Faculty_Title, Faculty_Profile_Link FROM suapp.FACULTY            
JOIN (
SELECT DISTINCT
suapp.RESEARCH_MATCH.Faculty_UUID
FROM suapp.RESEARCH_MATCH
JOIN suapp.AREA_TOPIC.Area_Topic_Code
ON suapp.RESEARCH_MATCH.Area_Topic_Code = suapp.AREA_TOPIC.Area_Topic_Code
WHERE suapp.RESEARCH_MATCH.Area_Topic_Code = suapp.AREA_TOPIC.Area_Topic_Code
AND suapp.AREA_TOPIC.Area_Topic_Code = 'CD-a'
) rm ON suapp.FACULTY.Faculty_UUID = rm.Faculty_UUID ORDER BY suapp.FACULTY.Last_Name, suapp.FACULTY.First_Name;

With your suggestion, the above is my new query that is getting the error (inside the sql console)
Thank you for your help.
debra
ASKER CERTIFIED SOLUTION
Avatar of ste5an
ste5an
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Awesome. Thank you for the help!
Debra