CODE
SELECT DISTINCT name.PER_ID as PERID, name.ENTITY_NAME as PER, id.ID_TYPE_CD, idssn.PER_ID_NBR, rel_l.DESCR12, name2.ENTITY_NAME as RLPER, name2.PER_ID as PERID2
FROM CM_RELSHIP rel
INNER JOIN CI_PER_NAME name ON rel.per_id1 = name.per_id
INNER JOIN CI_PER_ID id ON rel.per_id1 = id.per_id
INNER JOIN CI_PER_NAME name2 ON rel.per_id2 = name2.per_id
INNER JOIN CI_PER_REL_TYPE_L rel_l ON rel.per_rel_type_cd = rel_l.per_rel_type_cd
WHERE rel.PER_REL_TYPE_CD <> 'SPPR'
So here is my challenge right now...
This works but returns multiple lines per user because there are a possibility of a user having up to three different types of entrys in the in the CI_PER_ID table. I need it to now return all of the users ID's at once instead of listing them on separate lines. I messed with arrays but could not fine a way to pass all the values from a select distinct into an array so I thought I'd try different joins and I basically ended up with only the 20 or so users that actually have all 3 id's out of the 13000+ users. Any thoughts on how I may be able to do this? Is it possible to do entirely within SQL? Below is another attempt that gave me the result mentioned above.
[code]
SELECT DISTINCT name.PER_ID as PERID, name.ENTITY_NAME as PER, id1.ID_TYPE_CD, id1.PER_ID_NBR, id2.ID_TYPE_CD, id2.PER_ID_NBR, id3.ID_TYPE_CD, id3.PER_ID_NBR, rel_l.DESCR12, name2.ENTITY_NAME as RLPER, name2.PER_ID as PERID2
FROM CM_RELSHIP rel
INNER JOIN CI_PER_NAME name ON rel.per_id1 = name.per_id
INNER JOIN CI_PER_ID id1 ON rel.per_id1 = id1.per_id
INNER JOIN CI_PER_ID id2 ON rel.per_id1 = id2.per_id
INNER JOIN CI_PER_ID id3 ON rel.per_id1 = id3.per_id
INNER JOIN CI_PER_NAME name2 ON rel.per_id2 = name2.per_id
INNER JOIN CI_PER_REL_TYPE_L rel_l ON rel.per_rel_type_cd = rel_l.per_rel_type_cd
WHERE rel.PER_REL_TYPE_CD <> 'SPPR' and id1.id_type_cd = 'Val1' and id2.id_type_cd = 'Val2' and id3.id_type_cd = 'Val3'
[\code]
And to try to describe the tables breifly to clairfy...
CI_PER_NAME contains a users name and user_number.
CM_RELSHIP contains 2 user_numbers and relationship id.
CI_PER_ID contains a user_number, user_id_type and user_id (user_numbers may be in here 3 times with different user_id_type)
CI_PER_REL_TYPE contains a relationship type and relationship id.
and what I need out is User1Name, User1ID1, User1ID2, User1ID3, relationship, user2Name