Good day all,
Thanks for your help in advance! I need some advice on how I might construct a query from the following information. I have table of accounts and names, etc. that looks like this:
AcctNum Name
234567 Joe Cool
567891 Jane Doe
I am going to join it to an Insurance table that contains all the insurances and the order of those insurances applicable to the account. The order of the insurance is by number with "1" being primary insurance, "2" secondary, etc. I want to use a left join on the two tables so I get all the records from the account table so that those with no insurance are shown as well. This would look like the following if nothing else was needed:
AcctNum Name Fin Class Insurance InsOrder TotalCharge
234567 Joe Cool MDCR MDCR.A 1 1300
234567 Joe Cool MDCR MDCD.SC 2 1300
234567 Joe Cool MDCR BC.SC 3 1300
567891 Jane Doe MG.CASE BC.PPO 1 250
567891 Jane Doe MG.CASE MCCR.A 2 250
345678 Bill Jones SP.AP 1450
I would like the query to pull the record set so that one record per account displays as in the following:
AcctNum Name Fin Class PriIns SecIns OtherIns TotalCharge
234567 Joe Cool MDCR MDCR.A MDCD.SC BC.SC 1300
567891 Jane Doe MG.CASE BC.PPO MCCR.A 250
345678 Bill Jones SP.AP 1450
I understand that in order to get this output I will need to drop the insurance table into the designer 3 times in order to get the insurances in there horizontally instead of vertically... my problem is how to do the criteria so I don't filter out records without insurance based on criteria (ie. Insorder = 1... 2.. etc.) and how to get the null values to show where there are no secondary or other insurances as above. Do I use IIF function somehow in all this? I hope this is clear... and thanks again in advance for your help!
Thanks for your help in advance! I need some advice on how I might construct a query from the following information. I have table of accounts and names, etc. that looks like this:
AcctNum Name
234567 Joe Cool
567891 Jane Doe
I am going to join it to an Insurance table that contains all the insurances and the order of those insurances applicable to the account. The order of the insurance is by number with "1" being primary insurance, "2" secondary, etc. I want to use a left join on the two tables so I get all the records from the account table so that those with no insurance are shown as well. This would look like the following if nothing else was needed:
AcctNum Name Fin Class Insurance InsOrder TotalCharge
234567 Joe Cool MDCR MDCR.A 1 1300
234567 Joe Cool MDCR MDCD.SC 2 1300
234567 Joe Cool MDCR BC.SC 3 1300
567891 Jane Doe MG.CASE BC.PPO 1 250
567891 Jane Doe MG.CASE MCCR.A 2 250
345678 Bill Jones SP.AP 1450
I would like the query to pull the record set so that one record per account displays as in the following:
AcctNum Name Fin Class PriIns SecIns OtherIns TotalCharge
234567 Joe Cool MDCR MDCR.A MDCD.SC BC.SC 1300
567891 Jane Doe MG.CASE BC.PPO MCCR.A 250
345678 Bill Jones SP.AP 1450
I understand that in order to get this output I will need to drop the insurance table into the designer 3 times in order to get the insurances in there horizontally instead of vertically... my problem is how to do the criteria so I don't filter out records without insurance based on criteria (ie. Insorder = 1... 2.. etc.) and how to get the null values to show where there are no secondary or other insurances as above. Do I use IIF function somehow in all this? I hope this is clear... and thanks again in advance for your help!