Hey guys, my first post here. I've got a query that I am dynamically building using VB.NET and has become pretty complicated as its developed. There is a portion in the WHERE clause were if 1 code is not present, I need to search for another. Here is the query with some of the unecessary stuff trimmed out:SELECT DISTINCT A.state_num, A.section_code, A.sequence_num, B.claim_status, A.incurred_date, A.policy_date, Year(A.incurred_date) as incYear, Year(A.policy_date) as polYear, B.line_item, left(B.line_item,2) as Coverage FROM claim_header A INNER JOIN claim_detail B ON A.state_num = B.state_num AND A.section_code = B.section_code AND A.sequence_num = B.sequence_num WHERE report_date <= '12/31/2004' AND ((B.claim_status <> 'C' AND Left(B.line_item,2) IN ('11', '12', '19', '80', '41', '42', '71', '72', '73', '51', '52', '82')) OR (A.Claim_status <> 'C' AND ((A.section_code = 'WC' AND B.line_item = '990') OR (A.section_code = 'XW' AND B.line_item = '990')))) ORDER BY A.state_num, A.section_code, Coverage, incYear, A.sequence_num(A.section_code = 'XW' AND B.line_item = '990')This is the line I'm having troubles with. Under normal circumstances, ALL WC and XW records will have a 990 line_item. There will occaisionally be an instance however where an XW record will not. In those cases, I need to pull the 991 line_item. My problem here is that it's possible for both WC and XW records to have both a 990 and a 991. I need only the 990 in those cases where 1 exists and only the 991 if a 990 doesn't exist.Does that make sense? Thanks in advance for any help on this.