locked
Display null value for missing months in sql RRS feed

  • Question

  • User1042252450 posted

    Hello,

    I have two tables with records table A and table B.  I am using inner join in my query and code ,month & year will be in where condition.

    I need to get null value for missing months. I can't use left join. it has more records.

    Table A      
    Code Month Year values
    11 1 2015 100
    11 2 2015 101
    11 3 2015 200
           
    Table B      
    Code Month Year values
    11 1 2015 100
    11 3 2015 200
           

    Output:

    Code Month Year values
    11 1 2015 200
    11 2 2015 Null
    11 3 2015 400

    Please suggest.

    regards,

    rangasamy

    Thursday, March 17, 2016 4:03 PM

Answers

  • User77042963 posted
    Select a.Code,a.[Month],a.[Year], a.value+ b.values] as [values]
    from tableA a left join tableB b
    on a.Code=b.Code and a.[Month]=b.[Month] and a.[Year]=b.[Year]



    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, March 17, 2016 6:31 PM