How do you tell a SQL 2008 query to ignore certain rows?
I've run a query bringing in everything to see what I want to filter out. I need to show all employees in a particular division. Then I need show who has taught a particular class and who has not. Basically easy until you find screwy data. I need to get my query to ignore this screwy data. Following is a sample result set. The first User 2 row is the screwy data that I don't want to see. ![alt text] Here is my case statement that does work, but everything I've tried keeps giving the screwy data lines the 'Y' value. CASE WHEN TABLE2.COURSE_TITLE IS NOT NULL THEN'Y' WHEN TABLE1.ROLE = 'Teacher' AND TABLE2.COURSE_TITLE IS NULL THEN --... i don't want to see these rows returned at all. How do i tell it to ignore these? WHEN TABLE1.ROLE IS NULL THEN'N' END AS 'TAUGHT' Thank you! : /storage/temp/753-ignore.jpg
Your TSQL seems to point to more than one table being involved (Table1 and Table2 are mentioned) but we dont see how you are joining them or any other information - we will need more details about the tables to be more accurate with our answers. You should filter rows out of a recordset with the WHERE clause. What makes row 2 in your sample data a row that you dont want? If it is simply where a teacher has a NULL CourseTitle then you WHERE clause might be WHERE [NOT] (Table1.Role 'Teacher' and Table2.Course_Title IS NULL) with this filtering in the WHERE you should then simply use the Taught column values without the CASE statement