Hi all please find a query I am trying to get working. The problem I am having is that I am trying to use a date field from the subquery as part of a 'date difference' thing in the main query and its got me stumped. Any help appreciated
cheers Pete
select count (*) FROM client cl WHERE 1 = (select count (*)
FROM client cl, cytology_result cr1, test_result tr1
WHERE cl.clientid = tr.clientid AND cr1.resultid = tr1.resultid
AND cr1.squ_cd = '9'
AND (tr1.test_date - cytt.test_date) < 730
GROUP by cl.clientid)
AND exists(SELECT count (distinct cl.clientid)
FROM client cl, cytology_result cyt, test_result cytt
WHERE cl.clientid=cytt.clientid
AND cytt.resultid = cyt.resultid
AND cytt.test_type='C'
AND cyt.squ_cd = '3'
AND cyt.hpv_cd != '3'
AND cyt.end_cd not between '3' and '8'
AND cyt.oth_cd not between '2' and '8'
AND cytt.test_date > '01-JAN-1999'
AND cytt.test_date < '31-DEC-1999');
cheers Pete
select count (*) FROM client cl WHERE 1 = (select count (*)
FROM client cl, cytology_result cr1, test_result tr1
WHERE cl.clientid = tr.clientid AND cr1.resultid = tr1.resultid
AND cr1.squ_cd = '9'
AND (tr1.test_date - cytt.test_date) < 730
GROUP by cl.clientid)
AND exists(SELECT count (distinct cl.clientid)
FROM client cl, cytology_result cyt, test_result cytt
WHERE cl.clientid=cytt.clientid
AND cytt.resultid = cyt.resultid
AND cytt.test_type='C'
AND cyt.squ_cd = '3'
AND cyt.hpv_cd != '3'
AND cyt.end_cd not between '3' and '8'
AND cyt.oth_cd not between '2' and '8'
AND cytt.test_date > '01-JAN-1999'
AND cytt.test_date < '31-DEC-1999');