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

  • Home
  • SEARCH
  • 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 8964561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:37:04+00:00 2026-06-15T16:37:04+00:00

PROBLEM: Need the query to return the MONTH_NAME and YIELD for b.Monthly_Yield even when

  • 0

PROBLEM: Need the query to return the MONTH_NAME and YIELD for b.Monthly_Yield even when the Month_Name is NOT found in a.Month. For some reason, if the Month is not found in a.Month, even when I add to the selection b.month, the query still will not return the b.Monthly_Yield value. The way I have it now, if the MONTH is NOT found in table “a” but the month is found in table “b” the result will NOT return. I need the result to return for “b” even if that month is not found in “a”.

Note: “Month” is the Month Number

DATA RESULTS WITH LEFT OUTER JOIN:

Month  Month_Name  Yield_1  Yield_0
------------------------------------
2      Febrero     11.44    14
3      Marzo       NULL     3.21
4      Abril       NULL     14.24
7      Julio       NULL     10.36
8      Agosto      NULL     0
9      Septiembre  NULL     -9.6
10     Octubre     NULL     10.35
11     Noviembre   NULL     1.4
12     Diciembre   11.44    -1.18

DATA RESULTS WITH RIGHT OUTER JOIN:

Month  Month_Name  Yield_1  Yield_0
------------------------------------
NULL   NULL        11.44    NULL
2      Febrero     11.44    14
12     Diciembre   11.44    -1.18

Query:

SET @ID_CARTERA = 8;

select     
    a.Month,
    a.Month_Name,
    a.Monthly_Yield,
    b.Monthly_Yield

from
( select  
      RIGHT(A.F_ANOMES, 2) Month,
      IF(RIGHT(A.F_ANOMES, 2)=01,'Enero',
      IF(RIGHT(A.F_ANOMES, 2)=02,'Febrero',
      IF(RIGHT(A.F_ANOMES, 2)=03,'Marzo',
      IF(RIGHT(A.F_ANOMES, 2)=04,'Abril',
      IF(RIGHT(A.F_ANOMES, 2)=05,'Mayo',
      IF(RIGHT(A.F_ANOMES, 2)=06,'Junio',
      IF(RIGHT(A.F_ANOMES, 2)=07,'Julio',
      IF(RIGHT(A.F_ANOMES, 2)=08,'Agosto',
      IF(RIGHT(A.F_ANOMES, 2)=09,'Septiembre',
      IF(RIGHT(A.F_ANOMES, 2)=10,'Octubre',
      IF(RIGHT(A.F_ANOMES, 2)=11,'Noviembre',
      IF(RIGHT(A.F_ANOMES, 2)=12,'Diciembre',
      '')
      ))))))))))) Month_Name,

      ROUND(A.POR_RENTABILIDAD, 2) Monthly_Yield

from      dr_rent_carteras_meses A
where     A.ID_CARTERA = @ID_CARTERA
And       A.IND_RENTABILIDAD = 1
And       LEFT(A.F_ANOMES, 4) = ( select MAX(left(F_ANOMES, 4 ) ) - 0
                                  from dr_rent_carteras_meses
                                  where ID_CARTERA = @ID_CARTERA ) ) a

left outer join 
    ( select  
      RIGHT(A.F_ANOMES, 2) Month,
      IF(RIGHT(A.F_ANOMES, 2)=01,'Enero',
      IF(RIGHT(A.F_ANOMES, 2)=02,'Febrero',
      IF(RIGHT(A.F_ANOMES, 2)=03,'Marzo',
      IF(RIGHT(A.F_ANOMES, 2)=04,'Abril',
      IF(RIGHT(A.F_ANOMES, 2)=05,'Mayo',
      IF(RIGHT(A.F_ANOMES, 2)=06,'Junio',
      IF(RIGHT(A.F_ANOMES, 2)=07,'Julio',
      IF(RIGHT(A.F_ANOMES, 2)=08,'Agosto',
      IF(RIGHT(A.F_ANOMES, 2)=09,'Septiembre',
      IF(RIGHT(A.F_ANOMES, 2)=10,'Octubre',
      IF(RIGHT(A.F_ANOMES, 2)=11,'Noviembre',
      IF(RIGHT(A.F_ANOMES, 2)=12,'Diciembre',
      '')
      ))))))))))) Month_Name,

      ROUND(A.POR_RENTABILIDAD, 2) Monthly_Yield

from      dr_rent_carteras_meses A
where     A.ID_CARTERA = @ID_CARTERA
And       A.IND_RENTABILIDAD = 1
And       LEFT(A.F_ANOMES, 4) = ( select MAX(left(F_ANOMES, 4 ) ) - 1
                                  from dr_rent_carteras_meses
                                  where ID_CARTERA = @ID_CARTERA ) ) b on ( a.Month = b.Month )
  • 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-06-15T16:37:05+00:00Added an answer on June 15, 2026 at 4:37 pm

    Change LEFT OUTER JOIN to RIGHT OUTER JOIN.

    @ypercube is correct. Use FULL OUTER JOIN.

    The reason why you are not getting the month name is that there is now value in the a table. So you need to get it from the b table.

    Try

    ISNULL(a.Month, b.Month) as Month
    ISNULL(a.Month_Name, b.Month_Name) as Month
    

    Also, please take the advice of the comments. Use the correct data type functions. Also look into CASE statements.

    You also might want to query all the info in the join and then do the data conversion (month name) on the outside query. that way you don’t have to do it twice.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

PROBLEM: Need query to return the MONTH and YIELD for Each Year. For some
i have a problem with sql query. I need to get list of users.
Goal: Gain datatype date with year and month Problem: Need to help to convert
To solve some problem I need to compute a variant of the pascal's triangle
i got some problem and need help .. my plan : 1. get ip
Having a bit of a problem getting my LINQ query to return the object
I have a complex problem to solve with SQL query. I need to generate
I need my LINQ Query to return the Product Datatype, after being grouped. It
I need to query a table in an SQLite database to return all the
I have a query that needs to return results that are NOT matched in

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.