Here's a challenge for you experts:
I've got 3 tables:
Case
CaseID
CaseApp
CaseAppID
CaseID
Type
Date
CaseAppMember
CaseAppMemberID
CaseAppID
So as you can see from the above a Case has many CaseApps and a CaseApp has many CaseAppMembers.
My problem: I need to consolodate all of the CaseApps with the same Type and the same Date into 1.
This means I need to point all of the CaseAppMembers from the CaseApps that are to be deleted to the CaseApp that I am keeping (the first one).
I don't mind splitting this into 2 or 3 separate queries if it's easier - but can anyone help with this please?
Here's what I've got to show the numbers of CaseApps with the same date and type.
I've got 3 tables:
Case
CaseID
CaseApp
CaseAppID
CaseID
Type
Date
CaseAppMember
CaseAppMemberID
CaseAppID
So as you can see from the above a Case has many CaseApps and a CaseApp has many CaseAppMembers.
My problem: I need to consolodate all of the CaseApps with the same Type and the same Date into 1.
This means I need to point all of the CaseAppMembers from the CaseApps that are to be deleted to the CaseApp that I am keeping (the first one).
I don't mind splitting this into 2 or 3 separate queries if it's easier - but can anyone help with this please?
Here's what I've got to show the numbers of CaseApps with the same date and type.
Code:
-- Show the number of applications on a case where the type
-- and date are the same.
SELECT
COUNT(*),
C.CaseID,
CA.TypeID,
CA.Date
FROM
[Case] C
INNER JOIN CaseApp CA ON CA.CaseID = C.CaseID
GROUP BY
C.CaseID,
CA.TypeID,
CA.Date
ORDER BY
COUNT(*) DESC