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 7507383
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:28:37+00:00 2026-05-29T22:28:37+00:00

in my db model I have two entities: Entitlement and Entitlement_Data. Each Entitlement is

  • 0

in my db model I have two entities: Entitlement and Entitlement_Data. Each Entitlement is identified by an incrementing ID (IDENTITY), and can have multiple Entitlement_Data entries, each with a different Type – wich can be either 0 (Weekly) or 1 (Monthly) (EntitlementID and Type are PK for Entitlement_Data, EntitlementID being FK to Entitlement table).
For each Entitlement, I need to:

  1. Get the first non-NULL value from either Monthly (Type=1) or Weekly (Type=0) Entitlement_Data, for a given set of Entitlement_Data attributes (SharesPaid, LocalTaxRate, etc…) – the first part of the SELECT;
  2. Get some indication about match/mismatch between Monthly and Weekly Entitlement_Data entries (SharesPaid_Match, etc…) – the last part of the SELECT.

This is the query I’m using atm:

SELECT 
    COALESCE(MD.EntitlementID, WD.EntitlementID) AS EntitlementID,
    COALESCE(MD.LocalTaxRate, WD.LocalTaxRate) AS LocalTaxRate,
    COALESCE(MD.SharesPaid, WD.SharesPaid) AS SharesPaid,
    COALESCE(MD.LocalTaxAmount, WD.LocalTaxAmount) AS LocalTaxAmount,
    COALESCE(MD.LocalTaxEquivalent, WD.LocalTaxEquivalent) AS LocalTaxEquivalent,
    COALESCE(MD.NetReceived, WD.NetReceived) AS NetReceived,
    COALESCE(MD.LocalTaxCurrency, WD.LocalTaxCurrency) AS LocalTaxCurrency,
    COALESCE(MD.Currency, WD.Currency) AS Currency,
    COALESCE(MD.ReleaseDate, WD.ReleaseDate) AS ReleaseDate,
    (
        CASE
            WHEN MD.LocalTaxEquivalent IS NULL OR WD.LocalTaxEquivalent IS NULL THEN NULL
            WHEN MD.LocalTaxEquivalent <> WD.LocalTaxEquivalent THEN 0
            ELSE 1
        END
    ) AS LocalTaxEquivalent_Match,
    (
        CASE
            WHEN MD.NetReceived IS NULL OR WD.NetReceived IS NULL THEN NULL
            WHEN MD.NetReceived <> WD.NetReceived THEN 0
            ELSE 1
        END
    ) AS NetReceived_Match,
    (
        CASE
            WHEN MD.SharesPaid IS NULL OR WD.SharesPaid IS NULL THEN NULL
            WHEN MD.SharesPaid <> WD.SharesPaid THEN 0
            ELSE 1
        END
    ) AS SharesPaid_Match,
    (
        CASE
            WHEN MD.Currency IS NULL OR WD.Currency IS NULL THEN NULL
            WHEN MD.Currency <> WD.Currency THEN 0
            ELSE 1
        END
    ) AS Currency_Match,
    (
        CASE
            WHEN MD.DividendRate IS NULL OR WD.DividendRate IS NULL THEN NULL
            WHEN MD.DividendRate <> WD.DividendRate THEN 0
            ELSE 1
        END
    ) AS DividendRate_Match,
    (
        CASE
            WHEN MD.LocalTaxRate IS NULL OR WD.LocalTaxRate IS NULL THEN NULL
            WHEN MD.LocalTaxRate <> WD.LocalTaxRate THEN 0
            ELSE 1
        END
    ) AS LocalTaxRate_Match
FROM 
    Entitlement_Data MD
    FULL OUTER JOIN Entitlement_Data WD
        ON MD.EntitlementID = WD.EntitlementID
WHERE
    WD.Type = 0 AND MD.Type = 1

Is there a way to avoid FULL OUTER JOIN and obtain the informations I need? I evaluated the use of a GROUP BY but I don’t seem to get the results I need.
Thank you.

  • 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-29T22:28:38+00:00Added an answer on May 29, 2026 at 10:28 pm

    Why don’t you left join to “main table” which is Entitlement like in following code:

    select
        COALESCE(MD.EntitlementID, WD.EntitlementID) AS EntitlementID,
        COALESCE(MD.LocalTaxRate, WD.LocalTaxRate) AS LocalTaxRate,
        COALESCE(MD.SharesPaid, WD.SharesPaid) AS SharesPaid,
        COALESCE(MD.LocalTaxAmount, WD.LocalTaxAmount) AS LocalTaxAmount,
        COALESCE(MD.LocalTaxEquivalent, WD.LocalTaxEquivalent) AS LocalTaxEquivalent,
        COALESCE(MD.NetReceived, WD.NetReceived) AS NetReceived,
        COALESCE(MD.LocalTaxCurrency, WD.LocalTaxCurrency) AS LocalTaxCurrency,
        COALESCE(MD.Currency, WD.Currency) AS Currency,
        COALESCE(MD.ReleaseDate, WD.ReleaseDate) AS ReleaseDate,
        (
            CASE
                WHEN MD.LocalTaxEquivalent IS NULL OR WD.LocalTaxEquivalent IS NULL THEN NULL
                WHEN MD.LocalTaxEquivalent <> WD.LocalTaxEquivalent THEN 0
                ELSE 1
            END
        ) AS LocalTaxEquivalent_Match,
        (
            CASE
                WHEN MD.NetReceived IS NULL OR WD.NetReceived IS NULL THEN NULL
                WHEN MD.NetReceived <> WD.NetReceived THEN 0
                ELSE 1
            END
        ) AS NetReceived_Match,
        (
            CASE
                WHEN MD.SharesPaid IS NULL OR WD.SharesPaid IS NULL THEN NULL
                WHEN MD.SharesPaid <> WD.SharesPaid THEN 0
                ELSE 1
            END
        ) AS SharesPaid_Match,
        (
            CASE
                WHEN MD.Currency IS NULL OR WD.Currency IS NULL THEN NULL
                WHEN MD.Currency <> WD.Currency THEN 0
                ELSE 1
            END
        ) AS Currency_Match,
        (
            CASE
                WHEN MD.DividendRate IS NULL OR WD.DividendRate IS NULL THEN NULL
                WHEN MD.DividendRate <> WD.DividendRate THEN 0
                ELSE 1
            END
        ) AS DividendRate_Match,
        (
            CASE
                WHEN MD.LocalTaxRate IS NULL OR WD.LocalTaxRate IS NULL THEN NULL
                WHEN MD.LocalTaxRate <> WD.LocalTaxRate THEN 0
                ELSE 1
            END
        ) AS LocalTaxRate_Match
    from Entitlement e
    left join Entitlement_Data wd on e.id = wd.entitlementID and wd.type = 0
    left join Entitlement_Data md on e.id = md.entitlementID and md.type = 1
    

    You might limit to rows in Entitlement that have at last one row in Entitlement_Data table (without caring whether is weakly or monthly) using:

    where wd.type is not null or md.type is not null
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can i have two entities in the same model , but in different entities
In my Core Data model I have two entities: List and Patient. List has
I have a parent entity in my model Event. And two child entities: Birthday,
I have two model: User, Article A user can like or dislike many articles,
I have two tables related: DataEntered and Model DataEntered -currentModel Model One DataEntered can
I have a simple entity data model where I have two entities and a
OK so I have two entities in my data model (let's say entityA and
I have the following core data model with two entities: entity item which holds
I have created a core data model that has two entities which have a
I have a core data model that has two entities, Bid and Result. I

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.