Skip to content
Advertisement

SQL – a member can see a doctor only once a year

I have a table named Claim.

enter image description here

I have built the following query except the last column(Reimburse). How do I populate Reimburse column like this table?

So the idea is that company pays a member to see a doctor only if it’s been more than a year since his last “reimbursed” visit(reimburse = 1). ClaimID C2 is denied because 10/10/2017 is less than 12 months from his last visit in 3/20/2017. ClaimID C3 is approved because DOS is more than 12 months from his last APPROVED visit(C1) – even though it’s been less than 12 months from his last (unapproved) visit (c2).

Sorry, if my question is confusing.

DOS = date of service

Advertisement

Answer

Try this below logic-

Solution using CURSOR-

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement