How to join the start date to another data if it not matched

  • What if there is more than one 'Period Key' for a (Support_Start_Date, Support_End_Date) pair?

    Maybe you're looking for something like this?  It returns multiple rows if the (Support_Start_Date, Support_End_Date) pair spans multiple 'Period Key'

    select i.inv_Crd_No, 
    pr.Year_Num as Start_Year,
    pr.Month_Num as Start_Month,
    pr.Period_Key as Supp_start_key,
    i.Support_Start_Date,
    i.Support_End_Date
    from invoice_Credit_Fact i
    left join Period_Ref pr ON i.Support_Start_Date >= pr.[Start_Date]
    and i.Support_End_Date = pr.End_Date
    where i.inv_Crd_No iN ('SiN020693','SiN020685')
    order by i.inv_Crd_No, i.Support_Start_Date;

     

     

    Aus dem Paradies, das Cantor uns geschaffen, soll uns niemand vertreiben können

  • LEFT JOIN Period_Ref SD ON I.Support_Start_Date = SD.START_DATE

    LEFT JOIN Period_Ref ED ON SD.START_DATE IS NULL AND I.Support_END_Date = ED.END_DATE

     

    _____________
    Code for TallyGenerator

Viewing 2 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply