Click here to Skip to main content
15,894,343 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
SELECT PS_STUDENTS.STUDENT_NUMBER AS [sourcedId], PS_U_STUDENTSUSERFIELDS.O365_EMAIL AS [username], PS_STUDENTS.FIRST_NAME AS [givenName], PS_STUDENTS.LAST_NAME AS [familyName], PS_U_STUDENTSUSERFIELDS.O365_EMAIL AS [email], PS_SCHOOLS.SCHOOL_NUMBER AS [orgs], PS_STUDENTS.STUDENT_NUMBER AS [password], "Student" AS role, PS_CC.Course_Number INTO StudentUsers
FROM ((PS_STUDENTS 
INNER JOIN PS_U_STUDENTSUSERFIELDS ON PS_STUDENTS.DCID = PS_U_STUDENTSUSERFIELDS.STUDENTSDCID) 
INNER JOIN PS_SCHOOLS ON PS_STUDENTS.SCHOOLID = PS_SCHOOLS.SCHOOL_NUMBER) 
INNER JOIN PS_CC ON PS_STUDENTS.ID= PS_CC.STUDENTID
WHERE PS_CC.COURSE_NUMBER="HS0321H" 
OR PS_CC.COURSE_NUMBER= "HS0363"
OR PS_CC.COURSE_NUMBER= "HS0363"
OR PS_CC.COURSE_NUMBER="HS0320H"
OR PS_CC.COURSE_NUMBER="HS0321H"
OR PS_CC.COURSE_NUMBER= "HS0362"
OR PS_CC.COURSE_NUMBER= "HS0360"
OR PS_CC.COURSE_NUMBER="HS0358S1"
OR PS_CC.COURSE_NUMBER="HS0359S2"
OR PS_CC.COURSE_NUMBER= "HS0346"
OR PS_CC.COURSE_NUMBER="HS0353S1"
OR PS_CC.COURSE_NUMBER="HS0353S2"
OR PS_CC.COURSE_NUMBER="HS0352"
AND PS_STUDENTS.SCHOOLID= 1050 OR PS_STUDENTS.SCHOOLID=1075
AND PS_STUDENTS.ENROLL_STATUS= 0
AND PS_CC.TERMID=3100;

Any Idea, Pulling in everything correctly except I want just these students that have this course number pulled in.

What I have tried:

Changed around parentheses and wording. Also pulling in duplicates.
Posted
Updated 5-Nov-21 6:28am

We cannot help you.
You need access to that code and yoru data - and we don't have access to the later.

So it's going to be up to you.
I'd start by looking at the data, and executing that query against it in SSMS to see exactly what it did return.
If it is nothing, then then remove the WHERE condition - just comment it out - and try again. What do you get this time?
If it's nothing, the problem in the Join(s) so start commenting them out until you find which one causes a problem.
If it's something, then it's the WHERE clause, or part of it, so start adding a bit back and see when it goes.

Then you can focus on the data and find out why - but we can't do any of that for you!
 
Share this answer
 
Operator Precedence (Transact-SQL) - SQL Server | Microsoft Docs[^]

AND takes precedence over OR, just like multiplication does over addition.
You'll need several parentheses to get what you want.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900