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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:49:59+00:00 2026-05-23T11:49:59+00:00

I hv two tables:- First Table:- EFF_DATE RATE CURRENCY TYPE 20110101 1.286 USD 1

  • 0

I hv two tables:-

First Table:-
EFF_DATE     RATE   CURRENCY    TYPE
20110101     1.286  USD         1
20110101     1.300  USD         2
20110201     1.275  USD         1
20110201     1.290  USD         2
20110301     1.275  USD         1
20110301     1.285  USD         2
20110401     1.260  USD         1
20110401     1.270  USD         2
20110501     1.225  USD         1
20110501     1.230  USD         2

2nd Table:-

PO_NO   TRANS_DATE  ACCT_DATE   SUPP_NO CURRENCY     LOCAL_AMT 
1000068 20110114    20110115    S016    USD          16,500.00 
1000070 20110214    20110215    S016    USD           7,660.00 
1000072 20110317    20110322    S025    USD           1,080.00 
1000132 20110314    20110315    S037    USD           3,500.00 
1000133 20110414    20110415    S038    USD          14,500.00 

Based on ACCT_DATE & TYPE = 1, I wish to add a RATE column & the result should look like this:-

PO_NO   TRANS_DATE  ACCT_DATE   SUPP_NO CURRENCY     LOCAL_AMT  RATE
1000068 20110114    20110115    S016    USD          16,500.00  1.286
1000070 20110214    20110215    S016    USD           7,660.00  1.275
1000072 20110317    20110322    S025    USD           1,080.00  1.275
1000132 20110314    20110315    S037    USD           3,500.00  1.275
1000133 20110414    20110415    S038    USD          14,500.00  1.26
1000170 20110531    20110531    S016    USD          15,400.00  1.225

I used the below SQL to run but for some reasons, it just keep looping without any output:-

SELECT st.*, ft.rate
FROM second_table st
LEFT JOIN first_table ft 
    ON (MONTH(acct_date) = MONTH(eff_date) AND YEAR(acct_date) = YEAR(eff_date) )
where ft.TYPE=1

Pls help.

Thanks.

  • 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-23T11:50:00+00:00Added an answer on May 23, 2026 at 11:50 am

    Not very large. If I remove ft.TYPE=1,
    it will generate the result almost
    immediately.

    Based on your comment above you need to put an index on ft.TYPE

    You could also set up the query like this which might improve how the optimizer runs the query

    SELECT st.*, ft.rate
    FROM second_table st
    LEFT JOIN first_table ft 
        ON ft.TYPE=1 AND MONTH(acct_date) = MONTH(eff_date) AND YEAR(acct_date) = YEAR(eff_date)
    

    Also, are the dates stored as strings or as datetime values. If they are stored as strings you should do a string compare instead of coverting to datetimes and then extracting the month and year.

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

Sidebar

Related Questions

I have two tables and I need to remove rows from the first table
I have two tables with FIRST and SECOND id. <TABLE ID=FIRST> <TR> <TD></TD> <TD></TD>
I need UNION two tables with creating new field, where 1 for first table,
I have two tables, both with the same columns. The first table contains original
I have SQL Server 2008 database with two tables. The first table is called
I have a view that is joining two tables and ordering by the first
I am comparing between two tables first column each. If there is find a
Here's what I'm trying to accomplish: I've got two tables, call them first and
Two tables: COURSE_ROSTER - contains COURSE_ID as foreign key to COURSES USER_ID as field
Consider two tables transaction and category each having their own ID and information. A

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.