Closest date

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Tzep
    New Member
    • Mar 2012
    • 1

    #1

    Closest date

    Hi. This is my first post, so, please, bear with me.
    I have two tables:
    FIRST:
    Code:
    [B][U]ID[/U]    [U]DataEmitere[/U]    [U]DispIO[/U][/B]
     1    19.10.2011     0,00
     2    19.10.2011     0,00
     3    19.10.2011     0,00
     4    19.10.2011     0,00
     5    19.10.2011     0,00
     6    19.10.2011     0,00
     7    24.10.2011     0,00
     8    24.10.2011     0,00
     9    24.10.2011     0,00
    10    24.10.2011     0,00
    11    24.10.2011     0,00
    12    31.10.2011     0,00
    13    31.10.2011     0,00
    14    14.11.2011     0,00
    15    14.11.2011     0,00
    16    18.11.2011     0,00
    17    18.11.2011     0,00
    18    18.11.2011     0,00
    19    18.11.2011     0,00
    20    23.11.2011     0,00
    21    23.11.2011     0,00
    22    23.11.2011     0,00
    23    23.11.2011     0,00
    24    29.11.2011     0,00
    25    29.11.2011     0,00
    26    30.11.2011     0,00
    27    06.12.2011     0,00
    28    09.12.2011     0,00
    29    09.12.2011     0,00
    30    09.12.2011     0,00
    31    09.12.2011     0,00
    32    09.12.2011     0,00
    33    13.12.2011     0,00
    34    13.12.2011     0,00
    35    15.12.2011     0,00
    36    15.12.2011     0,00
    37    15.12.2011     0,00
    38    15.12.2011     0,00
    39    22.12.2011     0,00
    40    22.12.2011     0,00
    SECOND:
    Code:
    [B][U]ID[/U]    [U]Data[/U]    [U]Suma[/U][/B]
     1    01.10.2011    17.027,76 lei
     2    14.10.2011    4.121,00 lei
     3    19.10.2011    5.355,00 lei
     4    24.10.2011    3.645,00 lei
     5    26.10.2011    4.964,00 lei
     6    31.10.2011    3.402,00 lei
     7    14.11.2011    2.196,00 lei
     8    18.11.2011    8.844,00 lei
     9    23.11.2011    5.122,00 lei
    10    29.11.2011    8.829,00 lei
    11    13.12.2011    4.050,00 lei
    12    15.12.2011    3.700,00 lei
    13    21.12.2011    6.162,00 lei
    14    22.12.2011    3.260,00 lei
    I would like, if possible, to insert values from the second table into the first on, according to "Data" field from both. The trick is that, the second table contains less rows and different dates than the first one.
    Ex: TABLE 2 - Sum(ROW 1,2,3) --> TABLE 1 - ROW 1
    TABLE 2 - ROW 4 --> TABLE 1 - ROW 7
    TABLE 2 - Sum(ROW 5,6) --> TABLE 1 - ROW 12
    ... and so on.

    The question is: can I do that with SQL or with VBA?
    Last edited by NeoPa; Mar 6 '12, 07:01 AM. Reason: Reformatted to display better.
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    I have no idea how you're linking the two tables. It's unclear from your description.

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32669

      #3
      The answer is probably "Yes", but the question, though you've clearly put some effort into it, is not very clear.

      Please explain the logic you are working to so that it makes sense. Example data is good, but is only useful to pad out or clarify an explanation. It's no good to use in place of one.

      Comment

      • Mihail
        Contributor
        • Apr 2011
        • 759

        #4
        Welcome to the forum, Tzeposule !
        May I ask you why Sum(ROW 1,2,3) from Table 2 must go to Row 1 in Table 1 ? Why not in row 2 ? Or 3 or 4 ? For me looks the same (except the ID, o course).

        More than: In what field in Table 1 you wish to put the result ?

        I think is better to explain what you wish to achieve. And how you plan to do this (your logic).

        I wish to remember that the forum rules say that you must answer in English.
        If you wish to explain better in Romanian language you can send me a private message.
        I wish to warn you: If you do that (send me PM) yo also must explain your problem HERE, in English.

        Good luck !

        Comment

        Working...