Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6573719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:10:10+00:00 2026-05-25T15:10:10+00:00

I wasn’t sure what could be the title for my question so sorry about

  • 0

I wasn’t sure what could be the title for my question so sorry about that.

I’m trying to write a SQL query to achieve the no. of members who should get reimbursed from a pharmacy.

For example : I went to pharmacy, I took a vaccine but by mistake I paid from my pocket. so now Pharmacy needs to reimburse me that amount. Lets say I have the data like:

MemberId  Name       ServiceDate    PresNumber    PersonId    ClaimId  AdminFee(in $)

   1      John        1/1/2011           123        345          456         0 
   1      John        1/21/2011          123        345          987        20
   2      Mike        2/3/2011           234        567          342         0
   2      Mike        2/25/2011          234        567          564        30
   5      Linda       1/4/2011           432        543          575         0
   5      Linda       4/6/2011           987        543          890         0
   6      Sonia       2/6/2011           656        095          439         0

This data shows all members from that pharmacy who got reimbursed and who haven’t.

I need to find out the member having AdminFee 0 but i also need to check another record for the same member having same PresNumber, same PersonId where the ServiceDate falls within 30 Days of the Original Record.
If another record meets this criteria and the AdminFee field contains a value (is NOT 0) then it means that person has already been reimbursed. So from the data you can see John and Mike have already been reimbursed and Linda and Sonia need to be reimbursed.

Can anybody help me how to write an SQL query on this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T15:10:10+00:00Added an answer on May 25, 2026 at 3:10 pm

    You don’t mention what SQL engine you’re using, so here is some generic SQL. You’ll need to adapt the date math and the return of True/False ( in the second option) to whatever engine you’re using:

     -- Already reimbursed
     SELECT * FROM YourTable YT1 WHERE AdminFee = 0 AND EXISTS 
         (SELECT * FROM YourTable YT2 
            WHERE YT2.MemberID = YT1.MemberID AND 
                  YT2.PresNumber = YT1.PresNumber AND
                  YT2.ServiceDate >= YT1.ServiceDate - 30 AND 
                  AdminFee > 0)
    
     -- Need reimbursement
     SELECT * FROM YourTable YT1 WHERE AdminFee = 0 AND NOT EXISTS 
         (SELECT * FROM YourTable YT2 
            WHERE YT2.MemberID = YT1.MemberID AND 
                  YT2.PresNumber = YT1.PresNumber AND
                  YT2.ServiceDate >= YT1.ServiceDate - 30 AND 
                  AdminFee > 0)
    

    or

     -- Both in one.
     SELECT YT1.*, 
       CASE WHEN YT2.MemberID IS NULL THEN False ELSE True END AS AlreadyReimbursed 
       FROM YourTable YT1 JOIN YourTable YT2 ON 
          YT1.MemberID = YT2.MemberID AND 
          YT1.PresNumber = YT2.PresNumber AND 
          YT1.ServiceDate <= YT2.ServiceDate + 30 
        WHERE YT1.AdminFee = 0 AND YT2.AdminFee > 0)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Wasn't sure how to write a good title for this question... :) I'm new
I wasn't sure what to title this question. Here's my goal: On page one,
I wasn't really sure how to title the question, but consider the following lua
I wasn't even sure how to title this right. I have a page that
I wasn't sure how to word the question for this topic...sorry. I'm just starting
The title of this Question may not be accurate because I wasn't sure how
I wasn't sure how to title this question. I'm creating an RIA Services driven
I wasn't sure how to title this question. I create a UDP connection using
I wasn't sure exactly how to phrase the question Title. I have this block
Hello I wasn't quite sure how to title this question, but I'll explain why

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.