Query the data between two tables

Need help for query the data between two tables
Table 1: Time sheet
P.ID      P.Name EmpID HoursSpend DateTime
c12234  Test      25        4                06/12/2013
c12234  Test      25        7                06/13/2013
c12234  Test      25        8                06/15/2013
c12234  Test      5          3                06/21/2013
c12234  Test      2          5                07/15/2013
c12234  Test      25        4                07/21/2013
Table 2: cost table
EmpID  FromDate       ToDate         Rate
25         05/01/2013    06/30/2013    250
2         04/01/2013    05/31/2013      150
25         07/01/2013     09/30/2013    300 
Output
P.ID      P.Name EmpID HoursSpend DateTime       Rate   Total (HoursSond x Rate)
c12234  Test      25        4                06/12/2013    250     1000 (4*250)
c12234  Test      25        7                06/13/2013    250      1750
c12234  Test      25        8                06/15/2013    250      
2000
c12234  Test      25        4              07/21/2013     300       
1200
c12234  Test      2          5              07/15/2013    150          
750
===========================================     
Total                           28                                                 
6700
============================================
Here EmpID =2 don't have rate in the cost table on july month should be pick from last entry from cost table.

Hi Gopal,
According to your description, it seems that the output needn’t include the row when EmpID=2. Because the DateTime for it in Table1 doesn’t included between FromDate column and ToDate column. After testing the issue in my environment, we can refer to the
query like below to achieve your requirement:
SELECT time.*,cost.EmpID,cost.Rate,(time.HoursSpend * cost.Rate)as [Total (HoursSond x Rate)]
FROM [Time sheet] as time
INNER JOIN
[cost table]as cost
ON time.EmpID = cost.EmpID
AND time.DateTime BETWEEN cost.FromDate AND cost.ToDate
If there are any other questions, please feel free to ask.
Thanks,
Katherine Xiong
Katherine Xiong
TechNet Community Support

Similar Messages

  • Intervals, synchronize the data between two oracle tables located in diffe

    Hi Experts,
    Is there any way I can, at set intervals, synchronize the data between two oracle tables located in different servers? What is the software, if there is any? If there are steps I can follow, so much the better.
    Thanks!

    I'm not sure what you want to achieve here...
    I want to synchronize both the Servers , so that it can update HO servers as well as Factory Server with the complete data. Could you please elaborate a little bit more; basing on your description I could also tell you how to setup timesync for those two servers if I understand "complete data" as the current date and time...
    Also a lot of solutions are platform and version specific so it would help if you could indicate OS and Database Versions (4 digit).
    And I still fail to see what this has to do with forms. You might want to post your question to the Database General forum: General Database Discussions
    cheers

  • Need to find the Difference between two table

    Hello ,
    I have stucked in program as below scenario:-
    I have two tables of huge data of same structure in a same schema.I need to find the difference exact values in tables.
    By using MINUS we can find the difference between two table ,i need to find the what exact difference in the there values with colunm and value at that column.
    Example TableA
    Col1 col2 col3 col4 col5.... col50
    10 ABC 2001 EE 444 TT
    40 XYZ 3002 RR 445 TT3
    80 DEF 6005 YY 446 YY8
    TableB
    Col1 col2 col3 col4 col5.... col50
    10 ABC 2001 EE 444 TT
    40 XYZ 3002 RR 445 TT3
    81 DEF 6005 Yu 447 YY8
    I need to the out put like this :-
    The Diffence between two table is
    TableA.COL1=80 TableB.Col1=81, Different
    TableA.Col4=YY TableB.col4=Yu,Different
    TableA.Col5=446TableB.col5=447,Different
    Please suggest me to write the pl/sql program for the same
    thanx in advance
    KK

    Thanx friends for all your efforts
    I have a sample code for the same,this will compare the two tables for single row in each table .
    what r the modification needed for the multiple rows of values in the two tables??
    Please suggest!!
    CREATE OR REPLACE PROCEDURE test_compare
    IS
    TYPE t_col
    IS
    TABLE OF VARCHAR2 (30)
    INDEX BY PLS_INTEGER;
    l_col t_col;
    j NUMBER := 0;
    l_sql VARCHAR2 (2000);
    col1 VARCHAR2 (30);
    col2 VARCHAR2 (30);
    val1 NUMBER;
    val2 NUMBER;
    status VARCHAR2 (30);
    CURSOR c1
    IS
    SELECT column_id, column_name
    FROM all_tab_columns
    WHERE table_name = 'TEST1';
    BEGIN
    FOR i IN c1
    LOOP
    j := j + 1;
    l_col (j) := i.column_name;
    END LOOP;
    FOR k IN 1 .. j
    LOOP
    l_sql :=
    'SELECT '
    || ''''
    || l_col (k)
    || ''''
    || ', '
    || 'TEST2.'
    || l_col (k)
    || ', '
    || ''''
    || l_col (k)
    || ''''
    || ', '
    || 'TEST1.'
    || l_col (k )
    || ', '
    || 'DECODE(TEST2.'
    || l_col (k)
    || ' -TEST1.'
    || l_col (k)
    || ', 0, ''NO CHANGE'', ''CHANGED'') FROM TEST2, TEST1';
    EXECUTE IMMEDIATE l_sql INTO col1, val1,col2, val2, status;
    IF status = 'CHANGED'
    THEN
    DBMS_OUTPUT.put_line( 'TEST2.'
    || col1
    || '='
    || val1
    || ', TEST1.'
    || col2
    || '='
    || val2
    || ', '
    || status);
    END IF;
    END LOOP;
    EXCEPTION
    WHEN OTHERS
    THEN
    DBMS_OUTPUT.put_line ('Error:- ' || SQLERRM);
    END;
    /

  • How to compare data between two tables?

    Hi,
    My team is trying to develop a SAP data migration tool (DMT) using ABAP.
    One of the functionalities in the DMT is to validate the data in the staging area against the loaded SAP data.
    The tables in the stagin area are customer tables (i.e. user-defined tables starting with Y, Z).
    How do I compare the data in the staging area against data that are loaded into SAP tables? Are there some built-in SAP functions to do this? Or, are there some better ways of doing this (e.g. instead of comparing against data in the SAP tables, we compare with some INTERNAL tables)?
    Any help would be greatly appreciated, thanks!

    Hi Kian,
    Use <b>SCMP</b> transaction to compare data between two tables and you can not use this for comparing internal tables.
    Thanks,
    Vinay

  • Select all the dates between two txt fields. how?

    In a 6i form cursor I need to select all the dates between two provided dates. I have two text fields FLD1 and FLd2 with date datatype. There is no table behind both the fields.
    For example
    :FLD1:='01-MAR-2013';
    :FLD2:='10-MAR-2013';
    Now I have to select all the dates from 01-mar-2013 to '10-mar-2013'. how to do it?

    Gul wrote:
    In a 6i form cursor I need to select all the dates between two provided dates. I have two text fields FLD1 and FLd2 with date datatype. There is no table behind both the fields.
    For example
    :FLD1:='01-MAR-2013';
    :FLD2:='10-MAR-2013';
    Now I have to select all the dates from 01-mar-2013 to '10-mar-2013'. how to do it?As'salamualikum Gul
    Try this
    SELECT TO_DATE('01-MAR-2013', 'DD-MON-RRRR') - 1 + rownum AS d
    FROM ALL_OBJECTS
    WHERE TO_DATE('01-MAR-2013', 'DD-MON-RRRR') - 1 + rownum BETWEEN TO_DATE('01-MAR-2013', 'DD-MON-RRRR') AND TO_DATE('10-MAR-2013', 'DD-MON-RRRR')Hope this helps

  • Transaction to see common data between two tables

    Is there any transaction to see common data between two tables with out creating views.
    what is the transaction to see the link between two tables
    regards
    pavan

    Hi,
            Go to a transparent table for which you want to know the common fields, from there click the button GRAPHICS (shortcut Ctrl + Shift + F11) in the application tool bar. Then you are redirected to a list containing the tables belonging to the same group. There select whatever tables you would like to see and click COPY. A window will pop-up and will show the relationship between the fields of the tables in a flow chart format.
    see to this link also.
    Common fields b/w  tables
    Regards,
    Revathi Bhoopal.

  • Insert the data into two tables at a time.

    Hi ,
    i have these two tables
    create table [dbo].[test1](
    [test1_id] [int] identity(1,1) primary key,
    [test2_id] [int] not null
    create table [dbo].[test2](
    [test2_id] [int] identity(1,1) primary key,
    [test1_id] [int] not null
    alter table [dbo].[test1]
    add constraint [fk_test1_test2_id] foreign key([test2_id])
    references [dbo].[test2] ([test2_id])
    alter table [dbo].[test2] add constraint [fk_test2_test2_id] foreign key([test1_id])
    references [dbo].[test1] ([test1_id])
    I want to insert the data into two tables in one insert statement. How can i do this using T-SQL ?
    Thanks in advance.

    You can INSERT into both tables within one Transaction but not in one statement. By the way, you would need to alter your dbo.Test1 table to allow null for first INSERT test2_id column
    See sample code below:
    CREATE TABLE #test1(test1_ID INT IDENTITY(1,1),test2_id INT NULL)
    CREATE TABLE #test2(test2_ID INT IDENTITY(1,1),test1_ID INT)
    DECLARE @Test1dentity INT
    DECLARE @Test2dentity INT
    BEGIN TRAN
    -- Insert NULL as test2_ID value is unknown
    INSERT INTO #test1(test2_ID)
    SELECT NULL;
    -- get inserted identity value
    SET @Test1dentity = SCOPE_IDENTITY();
    INSERT INTO #test2(test1_ID)
    SELECT @Test1dentity;
    -- get inserted identity value
    SET @Test2dentity = SCOPE_IDENTITY();
    -- Update test1 table
    UPDATE #test1
    SET test2_ID = @Test2dentity
    WHERE test1_ID = @Test1dentity;
    COMMIT
    SELECT * FROM #test1;
    SELECT * FROM #test2;
    -- Drop temp tables
    IF OBJECT_ID('tempdb..#test1') IS NOT NULL
    BEGIN
    DROP TABLE #test1
    END
    IF OBJECT_ID('tempdb..#test2') IS NOT NULL
    BEGIN
    DROP TABLE #test2
    END
    web: www.ronnierahman.com

  • To Select the data from two table one is transp table and onther is cluster

    Hi All,
    I want to select the data from two tables
    Here i am giving with an example.
    Fileds: kunnr belnr from bseg.  table bseg
    fields: adrnr from kna1     table: kna1.
    Know i want to put these into one internal table based on kunnr and belnr.
    Thanks in advance.
    Ramesh

    Hi,
       U cant use joins on cluster table and BSEG is a cluster table so use FOR  ALL ENTRIES for taht
    refer this code
    *&      Form  sub_read_bsak
          text
    -->  p1        text
    <--  p2        text
    FORM sub_read_bsak.
    *--Select data from BSAK Table
      SELECT lifnr
             augdt
             augbl
             gjahr
             belnr
             xblnr
             blart
             dmbtr
             mwskz
             mwsts
             sgtxt
             FROM bsak
             INTO CORRESPONDING FIELDS OF TABLE it_bsak
             WHERE belnr IN s_belnr
             AND   augdt IN s_augdt.
      IF sy-subrc EQ 0.
    *--Sort table by accounting document and vendor number
        SORT it_bsak BY belnr lifnr.
      ENDIF.
    ENDFORM.                    " sub_read_bsak
    *&      Form  sub_read_bseg
          text
    -->  p1        text
    <--  p2        text
    FORM sub_read_bseg.
      IF NOT it_bsak[] IS INITIAL.
    *--Select data from BSEG table
        SELECT belnr
               gjahr
               shkzg
               kostl
               hkont
               ebeln
               ebelp
               FROM bseg
               INTO CORRESPONDING FIELDS OF TABLE it_bseg
               FOR ALL ENTRIES IN it_bsak
               WHERE belnr EQ it_bsak-belnr
               AND   gjahr EQ it_bsak-gjahr
               AND   shkzg EQ 'S'.
        IF sy-subrc EQ 0.
    *--Sort table by accounting document
          SORT it_bseg BY belnr.
        ENDIF.
      ENDIF.
    ENDFORM.                    " sub_read_bseg

  • How can I get extract the data between two cursors on an XY graph

    How can I get extract the data between two cursors on an XY graph

    Well, you say xy graph, so this might be a more complicated problem.
    For a waveform graph it's trivial. Simply get the two cursor indices (property: cursor index) and apply them to array subset of the data. Is that all you need?
    Here's how the above code would look like. using cursor.index instead of cursor.x elimnates the need to include scaling information.
    For an xy graph, there could be multiple segments (e.g. imagine a spiral that passes the desired x range multiple times from both sides). This would neeed significantly more code for a general solution.
    Message Edited by altenbach on 11-24-2009 07:53 AM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    cursorsubset.png ‏17 KB

  • Fetch the data from two tables

    hell all
    i want to fetch the data from two tables, one is from internal table and another one is data base table. what syntax i have to use either FOR ALL ENTRIES or INNER JOIN?

    hi
    Use FOR ALL ENTRIES.
    see the sample code
      select * into table tvbrk from vbrk
                                where fkart in ('F2', 'F3', 'RE',
                                           'ZVEC' , 'ZVEM' , 'ZVED',
                                           'S1')
                                and erdat in so_erdat
                                and kunag in s_kunag. 
                                      erdat in so_erdat
                               and   fkart in ('F2', 'F3', 'RE',
                                                 'ZVEC' , 'ZVEM').
    if not tvbrk is initial.
        select * into table t_zregion from zregion
                      for all entries in tvbrk
                       where country = tvbrk-land1
                       and   region = s_regio.
      endif.
    thanks
    sitaram

  • SQL - Can u print all the dates between two given dates (Without PL/SQL)

    Hi Friends,
    I want to know if u can print all the dates between two given dates without using pl/sql.
    date1,date2 are given
    write a sql statement to display all the dates lying between those two dates.
    An earlier will be appreciated.
    Thanks in Advance
    Sriram
    null

    Sriram,
    Try this....
    select to_date('01-JAN-00')+to_number(rownum)
    from all_tables
    where rownum < to_date('10-JAN-00')-to_date('01-JAN-00')
    TO_DATE('
    02-JAN-00
    03-JAN-00
    04-JAN-00
    05-JAN-00
    06-JAN-00
    07-JAN-00
    08-JAN-00
    09-JAN-00

  • How to share the data between two or more frames

    How to share the data between two or more frames based on the database relationship in JDeveloper?

    You can pass data between frames by passing it as parameters.
    That is when you are invoking another frame, pass your data as arguments through the constructor to that frame .
    You can also achieve this through static or public methods, but static variables as we know is not suggested which might occupy more memory space.
    Regards,
    Srinivasan AShwath
    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by [email protected]:
    How to share the data between two or more frames based on the database relationship in JDeveloper? <HR></BLOCKQUOTE>
    null

  • How to get the data between two dates?

    Hi all,
    I am facing a problem of getting the data betwwen two dates.
    I have written a query as
    "select * from table1 a where a.dt between trunc(sysdate) and trunc(sysdate)-30"
    It is not showing any errors or warnings.But the data is not coming though the data is in the table1 between these two dates.
    Regards,
    Kumar

    Your ordering is probably wrong:
    SELECT *
      FROM table1 a
    WHERE a.dt BETWEEN TRUNC (SYSDATE) - 30 AND TRUNC (SYSDATE)

  • How do you find the average value of all the data between two points on a single channel

    I am tring to calculate the average value of all the data points on a single plot between two seperate points
    I have attahced an illustration.
    Tim
    Solved!
    Go to Solution.
    Attachments:
    plot.jpg ‏173 KB

    Hey smoothdurban,
    I've seen Brad's code, and trust me, it's worth the effort to let him help you get it up and running - it's definitely the most ideal way to solve this problem.  However, as Brad said, there are multiple ways to tackle this - both interactive and programmatic - so in the meantime, I'll take a second to detail one of the interactive and sure-fire ways to find the average of data between two points on a single channel.
    We'll use"Flags."  Set up your VIEW graph exactly as you did on your original screenshot, using Band Cursors to approximate the beginning and ending X-values representing the range you want to examine.  Next:
    1. Click the "Set Flags" button () that is a part of your 2D Axis System.  Note that you can hold down the Shift button if you ever decide you want to do this on more than a single curve at one time.
    2. Select the "Flags: Copy Data Points" button that enables after Flags are set.
    3. This creates new channel(s) in the default (bold) group in the Data Portal that contains only the Flagged data.
    4. Select DIAdem ANALYSIS.
    5. Select Statistics » Descriptive Statistics.
    6. In the Channels input, select the newly created channel containing your Flagged Y-Data.
    7. Ensure that the Arithmetic Mean parameter is set.  You can preview the data and the result in the dialog before pressing OK to execute the calculation. 
    You may have noticed that in the Descriptive Statistics calculation, one of the parameters that you can set is the range of channel rows to operate on - so, if you know the row numbers of your beginning and ending X-values, you could just simply run the Descriptive Statistics calculation and use this parameter to operate on a row subset of your original channel instead of the entire channel.
    Derrick S.
    Product Manager
    NI DIAdem
    National Instruments

  • How to get the dates between Two dates excluding Saturaday and Sunday

    Dear All,
    select to_date('25-04-2012', 'DD-MM-YYYY') + rownum -1 dt
        from dual
        connect by level <= to_date('05-05-2012', 'DD-MM-YYYY') - to_date('25-04-2012', 'DD-MM-YYYY') + 1;The above query returning the following output,
    DT
    DT
    04/25/2012
    04/26/2012
    04/27/2012
    04/28/2012
    04/29/2012
    04/30/2012
    05/01/2012
    05/02/2012
    05/03/2012
    05/04/2012
    05/05/2012here I need to exclude the Dates which comes on 'saturday' and 'sunday' and also the common holiday
    Here it is '01-May-2012' and I need the output like the following,
    04/25/2012
    04/26/2012
    04/27/2012
    04/30/2012
    05/02/2012
    05/03/2012
    05/04/2012I need the common query to calculate between any two dates.
    Can anyone suggest me?
    Thank you,
    Regsrds,
    gurujothi

    Hi Frank,
    Sorry for my fault,
    The following is my table description,
    CREATE TABLE  "DATES"
       (     "FROMDATE" DATE,
         "TODATE" DATE,
                       "LEAVE_ID" Number(5)
    Insert into dates values('05-02-2012','05-05-2012',1);
    Create table holiday_dates(holidays date);
    insert into holiday_dates values('01-05-2012');Now when I used this query,
    select count(*) from (select dt
    from(
        select to_date(fromdate, 'DD-MM-YYYY') + rownum -1 dt
            from dates
            connect by level <= to_date(todate, 'DD-MM-YYYY') - to_date(fromdate, 'DD-MM-YYYY') + 1
    where to_char(dt,'fmday') not in ('sunday','saturday') minus (select holidays from holiday_dates)) dual;
    Count(*)
       64
    Insert into dates values('01/05/2012','05/05/2012',2);
    /Now my table has 2 rows,
    select  *  from dates;
    FROMDATE     TODATE         LEAVE_ID
    01/05/2012     05/05/2012            1
    05/02/2012     05/05/2012            2Now when I used this query,
    select count(*) from (select dt
    from(
        select to_date(fromdate, 'DD-MM-YYYY') + rownum -1 dt
            from dates
            connect by level <= to_date(todate, 'DD-MM-YYYY') - to_date(fromdate, 'DD-MM-YYYY') + 1
    where to_char(dt,'fmday') not in ('sunday','saturday') minus (select holidays from holiday_dates)) dual;The output is ,
    COUNT(*)
    1987How to get the output using the max(leave_id) like the following,
    select..........from... where leave_id=(select max(leave_id) from dates);where to add "WHERE" clause in the above query?
    Thank you,
    Regards,
    Gurujothi.
    Edited by: Gurujothi on May 3, 2012 8:43 PM
    Edited by: Gurujothi on May 3, 2012 8:44 PM

Maybe you are looking for