Hi all,
I have the following SQL statement that works fine...
the produces a reults like this (I have supressed some of the columns to make it easier)
my problem is I need to add a column that counts the number of times an NHINO has one of these codes. So therefore in this case it will look like this...
Any ideas?
Cheers,
Kevin.
PS. My apologies for posting this on the ANSI SQL forum.
I have the following SQL statement that works fine...
Code:
SELECT distinct ANYBODYPAT.NHINO NHINO,
ANYBODYPAT.USERID USERID,
ANYBODYPAT.ETHCODE ETHCODE,
ANYBODYPAT.GENCODE GENCODE,
ANYBODYPAT.DOB DOB,
CLASSIFICATION.READCODE READCODE,
ANYBODYPAT.ISCAREPLUS ISCAREPLUS,
ANYBODYPAT.SERPROVCODE SERPROVCODE,
GEOCODE.QUINTILE DEP
FROM
((( CLASSIFICATION
LEFT JOIN USER ANYBODYPAT ON ANYBODYPAT.USERID= CLASSIFICATION.USERID)
LEFT JOIN ANYBODY ANYBODYANY ON ANYBODYANY.ANYBODYID = CLASSIFICATION.USERID)
LEFT JOIN GEOCODE ON GEOCODE.ANYBODYID = ANYBODYPAT.USERID)
WHERE CLASSIFICATION.ROWINACTIVE = 0 AND
(CLASSIFICATION.READCODE = 'C10.00' OR
CLASSIFICATION.READCODE = 'G3.00' OR
CLASSIFICATION.READCODE = 'G66.00' OR
CLASSIFICATION.READCODE = 'H3.00' OR
CLASSIFICATION.READCODE = 'H33.00' OR
CLASSIFICATION.READCODE = 'G65.00' OR
CLASSIFICATION.READCODE = 'G20.00' OR
CLASSIFICATION.READCODE = 'N330.00' OR
CLASSIFICATION.READCODE = 'C04.00' OR
CLASSIFICATION.READCODE = 'G580.00' OR
CLASSIFICATION.READCODE = 'E2B.00' OR
CLASSIFICATION.READCODE = 'C3135.00' OR
CLASSIFICATION.READCODE = 'C324.00')
AND
CLASSIFICATION.WHENCLASS IS NOT NULL AND
ANYBODYPAT.ENROLMENTFUNDINGCODE = 'F' AND
ANYBODYPAT.ETHCODE IS NOT NULL AND
ANYBODYPAT.GENCODE IS NOT NULL AND
ANYBODYPAT.DOB IS NOT NULL AND
ANYBODYPAT.GENCODE IS NOT NULL AND
ANYBODYPAT.GENCODE <> '' AND
ANYBODYPAT.USERID IS NOT NULL AND
ANYBODYPAT.NHINO IS NOT NULL AND
ANYBODYPAT.NHINO <> ''
the produces a reults like this (I have supressed some of the columns to make it easier)
Code:
NHINO | READCODE| ISCAREPLUS| SERPROVCODE
------------------------------------------
123 | C10.00 | Y | bob
123 | H33.00 | Y | bob
123 | G65.00 | Y | bob
456 | C10.00 | N | bill
456 | H3.00 | N | bill
789 | H33.00 | Y | ted
789 | G65.00 | Y | ted
853 | C10.00 | N | fred
853 | H3.00 | Y | fred
my problem is I need to add a column that counts the number of times an NHINO has one of these codes. So therefore in this case it will look like this...
Code:
NHINO | READCODE| ISCAREPLUS| SERPROVCODE | CODECOUNT
-----------------------------------------------------
123 | C10.00 | Y | bob | 3
123 | H33.00 | Y | bob | 3
123 | G65.00 | Y | bob | 3
456 | C10.00 | N | bill | 2
456 | H3.00 | N | bill | 2
789 | H33.00 | Y | ted | 2
789 | G65.00 | Y | ted | 2
853 | C10.00 | N | fred | 2
853 | H3.00 | Y | fred | 2
Any ideas?
Cheers,
Kevin.
PS. My apologies for posting this on the ANSI SQL forum.