object - Case Else Statement from different tables -
i trying retrieve name based on type of claim. seem easy enough, it's not working me. working 2 main tables, claim
, exposure
, , contactname
table. each claim
can have multiple exposures
, each exposure
can have 1 claim
. both tables contain nameid
field - claim.nameid
, exposure.nameid
. nameid
correlates contactname
table.
contact name
id name
111 jim
222 bob
333 john
444 sam
555 walt
normally, each claim
can have multiple exposures
, exposures
on claim
can have same name or different names. name ids
found on exposure
.
the exposure.nameid joins contactname.id
claim claim.nameid exposureno exposure.nameid name
a null 1 111 jim
a null 2 222 bob
a null 3 333 john
b null 1 444 sam
b null 2 444 sam
workers comp claims different. each workers comp claim can have multiple exposures, exposures have same name. since exposures on claim have same name, name ids found, not on exposure table, claim table. go figure… claim.nameid joins contactname.id claimcontactname.
claim claim.nameid exposureno exposure.nameid name
c 111 1 null jim
c 111 2 null jim
c 111 3 null jim
d 555 1 null walt
d 555 2 null walt
i can names non workers comp claims
, can names workers comp claims
. however, when put 2 queries together, don’t results.
select case when @select(claim\policy type) = 'workers'' compensation' case when claimcontact.name null , claimcontact.name.firstname null claimcontact.lastname when claimcontact.name not null claimcontact.name else claimcontact.firstname + space(1) + claimcontact.lastname end else case when contact.name null , contact.firstname null contact.lastname when contact.name not null contact.name else contact.firstname + space(1) + contact.lastname end end
haven’t done of this, use figure out. thank in advance.
Comments
Post a Comment