Duplicate records when joining Member, Gift and MembershipTransaction tables

Options
Hi, 


I am new to Raisers Edge and was trying to write a SQL query against the database to get the Gifts along with Gift Date and the corresponding MembershipTransaction. I am basically trying to do this in order to get the Memberships of a certain type directly from the database. I would really appreciate if someone can help me out with this. 


Please see query below that I am using:
select *


from MEMBER m 


inner join RECORDS r on r.ID = m.ConstitID 


inner join CONSTIT_GIFTS cg on cg.CONSTIT_ID = r.ID 


inner join GIFT g on g.ID = cg.GIFT_ID 


left join TABLEENTRIES te on te.TABLEENTRIESID = g.GIFT_CODE  


inner join MembershipTransaction mt on mt.MembershipID = m.ID 


inner join MembershipCategory mc on mc.MembershipCategoryID = mt.Category 


inner join USERS u on u.USER_ID = m.ADDED_BY 


where te.LONGDESCRIPTION like '%DMP - Membership%' 


--and m.Added_By in ('24','49')


order by m.ID,key_date, gift_date




Now the problem is that I am seeing duplicate records for a particular Member. For e.g. if  a Member X purchased and renewed Memberships on 4 different dates. I am seeing 16 records instead of just 4 records. For each Gift Date, there are 4 different transaction dates as a result of the INNER JOIN. Can someone please help me out with this? Again I am new to Raisers Edge and not sure what the right way to do this is. 


Thank you,

MK

Comments

  • Hi Malavika,


    Try restricting your SELECT columns and using DISTINCT.


    Cheers,

    Steve Cinquegrana | CEO and Principal Developer | Protégé Solutions

     
  • Steven Cinquegrana:

    Hi Malavika,


    Try restricting your SELECT columns and using DISTINCT.


    Cheers,

    Steve Cinquegrana | CEO and Principal Developer | Protégé Solutions

     

    Hi Steve, 


    Thank you for the response. I did try doing that but it still gives me duplicate columns.  


    -MK

  • That doesn't sound right; if I use your query and SELECT DISTINCT m.ID, etc I only get unique Membership IDs.


    If you expand the SELECT columns one-by-one, at some point you'll start to get duplicate rows and that will tell you which table join is causing the problems.


    A quick-and-dirty approach is to use the result of the original query as a sub-query but I'd really recommend the first approach.


    Cheers, Steve

     
  • Malavika Krishnaswamy:

    Steven Cinquegrana:

    Hi Malavika,


    Try restricting your SELECT columns and using DISTINCT.


    Cheers,

    Steve Cinquegrana | CEO and Principal Developer | Protégé Solutions

     

    Hi Steve, 


    Thank you for the response. I did try doing that but it still gives me duplicate columns.  


    -MK

     

    When using distinct are you getting the same number of dupes, or does the distinct reduce the number (per individual)?   We are hosted, so I do not have backend access, but when querying using the RE Query, I do know the gifts can be counted multiple times if they are Split Gifts.   Could that be your issue?

     

  • Larry Wheeler:

    Malavika Krishnaswamy:

    Steven Cinquegrana:

    Hi Malavika,


    Try restricting your SELECT columns and using DISTINCT.


    Cheers,

    Steve Cinquegrana | CEO and Principal Developer | Protégé Solutions

     

    Hi Steve, 


    Thank you for the response. I did try doing that but it still gives me duplicate columns.  


    -MK

     

    When using distinct are you getting the same number of dupes, or does the distinct reduce the number (per individual)?   We are hosted, so I do not have backend access, but when querying using the RE Query, I do know the gifts can be counted multiple times if they are Split Gifts.   Could that be your issue?

     

     

    The query I am using is as seen below:

     
    select distinct 


            m.ID as 'Membership ID', 


            m.Date_Joined as key_date,


    mt.ActivityDate as transaction_date,


    g.DTE as gift_date,


    g.CONSTIT_ID,


            r.FIRST_NAME + ' ' + r.LAST_NAME as 'Primary Member Name', 


            mc.MembershipCategoryID, 


            mt.Dues as 'Dues\\Amount',  


            m.Added_By, 


            u.NAME


            --te.LONGDESCRIPTION as 'Gift Code' 


    from MEMBER m 


    inner join RECORDS r on r.ID = m.ConstitID 


    inner join CONSTIT_GIFTS cg on cg.CONSTIT_ID = r.ID 


    inner join GIFT g on g.ID = cg.GIFT_ID 


    left join TABLEENTRIES te on te.TABLEENTRIESID = g.GIFT_CODE  


    inner join MembershipTransaction mt on mt.MembershipID = m.ID 


    inner join MembershipCategory mc on mc.MembershipCategoryID = mt.Category 


    inner join USERS u on u.USER_ID = m.ADDED_BY 


    where te.LONGDESCRIPTION like '%DMP - Membership%' 


    --and m.Added_By in ('24','49')


    order by m.ID,key_date, gift_date


    I am trying to get the Memberships by Gift Date along with the Activity Date from the MembershipTransaction table but when I add the join to the MembershipTransaction table, that is where the duplicates start appearing. For e.g. If there are 4 different Gifts and 4 different transaction dates, I am getting a total of 16 rows for one Member ID. 


    Thank you,

    MK


  • Malavika Krishnaswamy:

     

    The query I am using is as seen below:

     
    select distinct 


            m.ID as 'Membership ID', 


            m.Date_Joined as key_date,


    mt.ActivityDate as transaction_date,


    g.DTE as gift_date,


    g.CONSTIT_ID,


            r.FIRST_NAME + ' ' + r.LAST_NAME as 'Primary Member Name', 


            mc.MembershipCategoryID, 


            mt.Dues as 'Dues\\Amount',  


            m.Added_By, 


            u.NAME


            --te.LONGDESCRIPTION as 'Gift Code' 


    from MEMBER m 


    inner join RECORDS r on r.ID = m.ConstitID 


    inner join CONSTIT_GIFTS cg on cg.CONSTIT_ID = r.ID 


    inner join GIFT g on g.ID = cg.GIFT_ID 


    left join TABLEENTRIES te on te.TABLEENTRIESID = g.GIFT_CODE  


    inner join MembershipTransaction mt on mt.MembershipID = m.ID 


    inner join MembershipCategory mc on mc.MembershipCategoryID = mt.Category 


    inner join USERS u on u.USER_ID = m.ADDED_BY 


    where te.LONGDESCRIPTION like '%DMP - Membership%' 


    --and m.Added_By in ('24','49')


    order by m.ID,key_date, gift_date


    I am trying to get the Memberships by Gift Date along with the Activity Date from the MembershipTransaction table but when I add the join to the MembershipTransaction table, that is where the duplicates start appearing. For e.g. If there are 4 different Gifts and 4 different transaction dates, I am getting a total of 16 rows for one Member ID. 


    Thank you,

    MK

     

    The query issue ihere s the fact that you're linking to the gifts through constit_gifts and separately linking the membershiptransaction table, so it's going to pull ... I think it's called a cartesian product? of all the gift/transaction combinations. 


    What you need to do is link the gift to the transaction via the TransactionGift table, instead of using constit_gifts.  (edited yet again to add: you might need to do a subquery here actually, if you have both pledges and payments linked to membership gifts, so you don't double count them.)

  • Hi James, 


    Thank you so much for the response. I believe the CONSTIT_GIFTS table was present because if I try joining RECORDS and GIFTS directly using the AccountID and Record.ID, I am not seeing any results at all (Not sure why this is the case). Please see below the revised query that I tried using which did not work. I am not sure what you mean by sub-query. Again I am new to this so thank you for all the inputs. 


     

    select distinct m.ID as 'Membership ID', 


            m.Date_Joined as key_date,


    mt.ActivityDate as transaction_date,


    g.DTE as gift_date,


    g.CONSTIT_ID,


            r.FIRST_NAME + ' ' + r.LAST_NAME as 'Primary Member Name', 


            mc.MembershipCategoryID, 


            mt.Dues as 'Dues\\Amount',  


            m.Added_By, 


            u.NAME,


            te.LONGDESCRIPTION as 'Gift Code' 


    from MEMBER m 


    inner join RECORDS r on r.ID = m.ConstitID 


    inner join GIFT g on g.AccountID = r.ID 


    inner join TransactionGift tg on tg.GiftID = g.ID 


    left join TABLEENTRIES te on te.TABLEENTRIESID = g.GIFT_CODE  


    inner join MembershipTransaction mt on mt.ID = tg.TransactionID 


    inner join MembershipCategory mc on mc.MembershipCategoryID = mt.Category 


    inner join USERS u on u.USER_ID = m.ADDED_BY 


    where 


    te.LONGDESCRIPTION like '%DMP - Membership%'and 


    m.ID = 67978 


    and m.Added_By in ('24','49')


    order by m.ID,key_date, gift_date

    Thanks again, 
    MK




    James Andrews
    :

    Malavika Krishnaswamy:

     

    The query I am using is as seen below:

     
    select distinct 


            m.ID as 'Membership ID', 


            m.Date_Joined as key_date,


    mt.ActivityDate as transaction_date,


    g.DTE as gift_date,


    g.CONSTIT_ID,


            r.FIRST_NAME + ' ' + r.LAST_NAME as 'Primary Member Name', 


            mc.MembershipCategoryID, 


            mt.Dues as 'Dues\\Amount',  


            m.Added_By, 


            u.NAME


            --te.LONGDESCRIPTION as 'Gift Code' 


    from MEMBER m 


    inner join RECORDS r on r.ID = m.ConstitID 


    inner join CONSTIT_GIFTS cg on cg.CONSTIT_ID = r.ID 


    inner join GIFT g on g.ID = cg.GIFT_ID 


    left join TABLEENTRIES te on te.TABLEENTRIESID = g.GIFT_CODE  


    inner join MembershipTransaction mt on mt.MembershipID = m.ID 


    inner join MembershipCategory mc on mc.MembershipCategoryID = mt.Category 


    inner join USERS u on u.USER_ID = m.ADDED_BY 


    where te.LONGDESCRIPTION like '%DMP - Membership%' 


    --and m.Added_By in ('24','49')


    order by m.ID,key_date, gift_date


    I am trying to get the Memberships by Gift Date along with the Activity Date from the MembershipTransaction table but when I add the join to the MembershipTransaction table, that is where the duplicates start appearing. For e.g. If there are 4 different Gifts and 4 different transaction dates, I am getting a total of 16 rows for one Member ID. 


    Thank you,

    MK

     

    The query issue ihere s the fact that you're linking to the gifts through constit_gifts and separately linking the membershiptransaction table, so it's going to pull ... I think it's called a cartesian product? of all the gift/transaction combinations. 


    What you need to do is link the gift to the transaction via the TransactionGift table, instead of using constit_gifts.  (edited yet again to add: you might need to do a subquery here actually, if you have both pledges and payments linked to membership gifts, so you don't double count them.)

     

     

  • Malavika Krishnaswamy:

    Hi James, 


    Thank you so much for the response. I believe the CONSTIT_GIFTS table was present because if I try joining RECORDS and GIFTS directly using the AccountID and Record.ID, I am not seeing any results at all (Not sure why this is the case). Please see below the revised query that I tried using which did not work. I am not sure what you mean by sub-query. Again I am new to this so thank you for all the inputs. 


     

    select distinct m.ID as 'Membership ID', 


            m.Date_Joined as key_date,


    mt.ActivityDate as transaction_date,


    g.DTE as gift_date,


    g.CONSTIT_ID,


            r.FIRST_NAME + ' ' + r.LAST_NAME as 'Primary Member Name', 


            mc.MembershipCategoryID, 


            mt.Dues as 'Dues\\Amount',  


            m.Added_By, 


            u.NAME,


            te.LONGDESCRIPTION as 'Gift Code' 


    from MEMBER m 


    inner join RECORDS r on r.ID = m.ConstitID 


    inner join GIFT g on g.AccountID = r.ID 


    inner join TransactionGift tg on tg.GiftID = g.ID 


    left join TABLEENTRIES te on te.TABLEENTRIESID = g.GIFT_CODE  


    inner join MembershipTransaction mt on mt.ID = tg.TransactionID 


    inner join MembershipCategory mc on mc.MembershipCategoryID = mt.Category 


    inner join USERS u on u.USER_ID = m.ADDED_BY 


    where 


    te.LONGDESCRIPTION like '%DMP - Membership%'and 


    m.ID = 67978 


    and m.Added_By in ('24','49')


    order by m.ID,key_date, gift_date

    Thanks again, 
    MK

     

     

    Right, but you don't have to link the constituent and the gift directly -- you end up linking the gift to the constituent indirectly via the memership transaction.  I mean, haven't done a ton of membership querying but I think it's something more like:


    Member m

    left join records r on m.constit_id = r.id

    left join membershiptransaction mt on m.id = mt.membershipid

    left join transactiongift tg on mt.id = tg.transactionid

    left join gift g on tg.giftid = g.id


    etc. 


     

  • A good way to get started on direct SQL queries of the RE back-end database is to have a look at the SQL generated by RE for a similar, perhaps simpler, query using View/SQL (Ctrl-Q):

    6068796044f6e6a5957742162a70ec51-huge-26


    (For this you need the optional-but-usually-free RODBA module.)


    You can copy and paste this query into a new SQL Server Management Studio query pane (don't forget to "unpack" any sub-queries from the tabs starting with "DBO") and then run it, sometimes after a bit of fiddling. It will show you the table joins you'll need to replicate.


    Cheers,

    Steve Cinquegrana | CEO and Principal Developer | Protégé Solutions

     
  • Steven Cinquegrana:



    You can copy and paste this query into a new SQL Server Management Studio query pane (don't forget to "unpack" any sub-queries from the tabs starting with "DBO")



    You know, I've been Ctrl-Qing queries for years to yoink code from RE and I swear I never noticed that before. THANK YOU.
  • Sad to learn that the RODBA module is only available if you are self hosted....
  • Heather MacKenzie:

    Sad to learn that the RODBA module is only available if you are self hosted....

    True. But apparently there are other hosting providers besides blackbaud, who will allow you back end DB access. So if you really need to be hosted but you also need that access, you could look into one of them.

  • James Andrews: True. But apparently there are other hosting providers besides blackbaud, who will allow you back end DB access. So if you really need to be hosted but you also need that access, you could look into one of them.

    Agreed. You can also look at cloud providers such as Amazon AWS, which we use for our Blackbaud product demonstrations. We have a basic cloud server set up and can use it as if it were in the room next-door. It's a good middle option between self- and Blackbaud-hosted if you want 100% control of your access/data. I'm not sure if AWS does, but some cloud providers will also manage your backups.


    Cheers,

    Steve Cinquegrana | CEO and Principal Developer | Protégé Solutions

     

  • Can someone please let me know what is the estimated cost of RODBA module? I have tried looking for this information online but unable to find any details.  
  • Malavika Krishnaswamy:

    Can someone please let me know what is the estimated cost of RODBA module? I have tried looking for this information online but unable to find any details.  

    It is automatically included with certain levels of support/maintenance.

Categories