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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:41:57+00:00 2026-05-27T15:41:57+00:00

i have these tables: table 1 : date | idcurrency | total 2011-10-11 |

  • 0

i have these tables:

table 1:

   date     |   idcurrency   |   total
2011-10-11  |       1        |    100
2011-10-14  |       1        |    500
2011-10-12  |       2        |    200
2011-11-01  |       2        |    100

table 2

   idcurrency  |   value   |   date
       1       |    200    | 2011-10-09
       1       |    350    | 2011-10-15
       2       |    200    | 2011-10-09
       2       |    250    | 2011-10-20

I need to calculate a new total based on the multiplication of field total from the table 1, with the field value from the table 2.
Table 2 keep changes over the currency value and is not date continious, so I can’t figure out how to join these tables to get my goal


Change design

I was thinking in change the design of table2, adding a new field to save the final date of the range for the currency value, like this:

idcurrency | value |  start_date  |  end_date
     1        200     2011-10-09     2011-10-14
     1        350     2011-10-15     2011-12-14
     2        200     2011-10-09     2011-10-19
     2        250     2011-10-20     2011-12-14

Then, i could join table1 and table2 without use “outer apply”, but now am trying to make a query for add this new field

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-27T15:41:57+00:00Added an answer on May 27, 2026 at 3:41 pm

    You could use an outer apply subquery to search for the latest value for a currency:

    select  t1.*
    ,       last_value.Value * t1.total
    from    Table1 t1
    outer apply
            (
            select  top 1 value
            from    Table2 t2
            where   t2.idcurrency = t1.idcurrency
                    and t2.date <= t1.date
            order by
                    t2.date desc
            ) last_value
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have these two tables. Leave Table from_date to_date user_id 2011-12-01 2011-12-01 1 2011-12-01
Suppose you have these tables: Table Name: Salesman Fields: S_ID(Primary Key), Name Table Name:
If I have these two tables: <table> <tr> <td>Small Length Content</td> </tr> </table> <table>
Assume I have these tables, from which i need to display search results in
I have 2 tables A and B with following records --TABLE A-- id date
I have two tables 'Receipt Table:' and 'Person Table:' I need to find the
I have 3 tables; Table 1 id date 1 1132123123 2 1232342341 etc Table
I have two tables structured like this: table a id title date 1 testing1
I have these tables: CREATE TABLE User( Username varchar(15) NOT NULL, Name varchar(20) DEFAULT
i have these two simple tables: Invoices: ID       Date      ... 1    

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.