SQL tune for temp table

I am executing a query for which there is a system temp table is used, How could i tune for better execution?
Please see the execution plan below
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 25 | 2650 | 83 (2)| 00:00:01 |
|* 1 | COUNT STOPKEY | | | | | |
| 2 | NESTED LOOPS | | | | | |
| 3 | NESTED LOOPS | | 25 | 2650 | 83 (2)| 00:00:01 |
| 4 | NESTED LOOPS | | 25 | 1900 | 81 (2)| 00:00:01 |
| 5 | VIEW | | 603 | 28341 | 78 (2)| 00:00:01 |
| 6 | TEMP TABLE TRANSFORMATION | | | | | |
| 7 | LOAD AS SELECT | PRODUCTS | | | | |
| 8 | HASH UNIQUE | | 114 | 2736 | 1435 (2)| 00:00:18 |
|* 9 | HASH JOIN | | 114 | 2736 | 1434 (2)| 00:00:18 |
|* 10 | TABLE ACCESS FULL | CUSTOMERS | 65 | 780 | 865 (2)| 00:00:11 |
| 11 | TABLE ACCESS BY INDEX ROWID | ORDER_LINES | 252K| 2956K| 567 (1)| 00:00:07 |
|* 12 | INDEX RANGE SCAN | OL_O1 | 252K| | 85 (0)| 00:00:02 |
| 13 | SORT ORDER BY | | 603 | 81405 | 439 (3)| 00:00:06 |
| 14 | HASH GROUP BY | | 603 | 81405 | 439 (3)| 00:00:06 |
|* 15 | HASH JOIN RIGHT ANTI | | 603 | 81405 | 437 (2)| 00:00:06 |
| 16 | VIEW | | 114 | 912 | 2 (0)| 00:00:01 |
| 17 | TABLE ACCESS FULL | SYS_TEMP_0FD9D6B20_523F10 | 114 | 912 | 2 (0)| 00:00:01 |
|* 18 | HASH JOIN | | 604 | 76708 | 435 (2)| 00:00:06 |
| 19 | TABLE ACCESS BY INDEX ROWID | PRODUCTS | 411 | 8220 | 6 (0)| 00:00:01 |
|* 20 | INDEX RANGE SCAN | PR_U2 | 411 | | 1 (0)| 00:00:01 |
|* 21 | HASH JOIN | | 2177 | 227K| 428 (2)| 00:00:06 |
| 22 | NESTED LOOPS | | | | | |
| 23 | NESTED LOOPS | | 7348 | 423K| 325 (2)| 00:00:04 |
|* 24 | HASH JOIN | | 114 | 3078 | 176 (3)| 00:00:03 |
| 25 | VIEW | | 114 | 912 | 2 (0)| 00:00:01 |
| 26 | TABLE ACCESS FULL | SYS_TEMP_0FD9D6B20_523F10 | 114 | 912 | 2 (0)| 00:00:01 |
|* 27 | TABLE ACCESS FULL | CUSTOMER_CLUSTERS | 86315 | 1601K| 173 (2)| 00:00:03 |
|* 28 | INDEX RANGE SCAN | IDX_RULES_COMM_ANTE_PROB | 64 | | 1 (0)| 00:00:01 |
| 29 | TABLE ACCESS BY INDEX ROWID| RULES | 64 | 2048 | 1 (0)| 00:00:01 |
|* 30 | TABLE ACCESS FULL | CLUSTER_PRODUCTS | 18418 | 863K| 103 (1)| 00:00:02 |
| 31 | TABLE ACCESS BY INDEX ROWID | CUSTOMERS | 1 | 29 | 1 (0)| 00:00:01 |
|* 32 | INDEX UNIQUE SCAN | CU_PK | 1 | | 1 (0)| 00:00:01 |
|* 33 | INDEX UNIQUE SCAN | PR_PK | 1 | | 1 (0)| 00:00:01 |
| 34 | TABLE ACCESS BY INDEX ROWID | PRODUCTS | 1 | 30 | 1 (0)| 00:00:01 |
---------------------------------------------------------------------------------------------------------------------

ID 17 and 26
17 | TABLE ACCESS FULL | SYS_TEMP_0FD9D6B20_523F10 | 114 | 912 | 2 (0)| 00:00:01 |

Similar Messages

  • How to get SQL script for generating table, constraint, indexes?

    I'd like to get from somewhere Oracle tool for generating simple SQL script for generating table, indexes, constraint (like Toad) and it has to be Oracle tool but not Designer.
    Can someone give me some edvice?
    Thanks!
    m.

    I'd like to get from somewhere Oracle tool for
    generating simple SQL script for generating table,
    indexes, constraint (like Toad) and it has to be
    Oracle tool but not Designer.
    SQL Developer is similar to Toad and is an Oracle tool.
    http://www.oracle.com/technology/products/database/sql_developer/index.html

  • Tuning SQL Query for base tables

    Hi,
    Can any please help me to tune the below query...... there is full table scan for po_action_history table
    SELECT DISTINCT
         DECODE(hr.full_name,'Default Buyer, Purchasing','PCH',
    'Default Buyer, Travel','TRV',
    'Purchase Order, Rapid','RPO',
    'Data Interchange, Electronic','EDI',fuser1.user_name) BUYER_ID,
    poa.attribute1 BUYER_GROUP,
         poa.attribute2 BUYER_SUBGROUP
    FROM      po.po_action_history ac1,
         po.po_headers_all ph,
         po.po_agents poa,
         hr.per_all_people_f hr,
         applsys.fnd_user fuser1
    WHERE ph.po_header_id = ac1.object_id
    AND      ac1.object_type_code = 'PO'
    AND      ac1.action_code = 'APPROVE'
    AND      sequence_num =(SELECT MIN(ac2.sequence_num)
                   FROM po.po_action_history ac2,
                        applsys.fnd_user fuser2
    WHERE ph.po_header_id = ac2.object_id
    AND      ac2.object_type_code = 'PO'
    AND      ac2.action_code = 'APPROVE'
    AND      ac2.last_updated_by = fuser2.user_id)
    --AND  ac1.last_updated_by = fuser1.user_id
    AND      ph.agent_id = poa.agent_id
    AND      ph.agent_id = hr.person_id
    AND      hr.person_id = fuser1.employee_id
    AND      hr.effective_end_date > sysdate
    AND trunc(ac1.last_update_date) between '01-JAN-08' and '07-JAN-08'
    ORDER BY poa.attribute1
    Explain Plan
    PLAN_TABLE_OUTPUT
    Plan hash value: 3325319312
    Id Operation Name Rows
    Bytes Cost (%CPU) Time
    PLAN_TABLE_OUTPUT
    | 0 | SELECT STATEMENT | | 27 |
    2754 | 38963 (3) | 00:07:48 |
    | 1 | SORT UNIQUE | | 27 |
    2754 | 38962 (3) | 00:07:48 |
    |* 2 | FILTER | | |
    | | |
    |* 3 | HASH JOIN | | 37 |
    3774 | 36308 (3) | 00:07:16 |
    PLAN_TABLE_OUTPUT
    | 4 | TABLE ACCESS BY INDEX ROWID | FND_USER | 1 |
    13 | 2 (0) | 00:00:01 |
    | 5 | NESTED LOOPS | | 37 |
    3293 | 36303 (3) | 00:07:16 |
    | 6 | NESTED LOOPS | | 88 |
    6688 | 36180 (3) | 00:07:15 |
    | 7 | NESTED LOOPS | | 88 |
    PLAN_TABLE_OUTPUT
    3960 | 35916 (3) | 00:07:11 |
    |* 8 | TABLE ACCESS FULL | PO_ACTION_HISTORY | 2110 |
    71740 | 32478 (3) | 00:06:30 |
    | 9 | TABLE ACCESS BY INDEX ROWID | PO_HEADERS_ALL | 1 |
    11 | 2 (0) | 00:00:01 |
    |* 10 | INDEX UNIQUE SCAN | PO_HEADERS_U1 | 1 |
    | 1 (0) | 00:00:01 |
    PLAN_TABLE_OUTPUT
    | 11 | SORT AGGREGATE | | 1 |
    36 | | |
    | 12 | NESTED LOOPS | | 1 |
    36 | 6 (0) | 00:00:01 |
    |* 13 | TABLE ACCESS BY INDEX ROWID| PO_ACTION_HISTORY | 1 |
    31 | 6 (0) | 00:00:01 |
    |* 14 | INDEX RANGE SCAN | PO_ACTION_HISTORY_N1 | 5 |
    | 3 (0) | 00:00:01 |
    PLAN_TABLE_OUTPUT
    |* 15 | INDEX UNIQUE SCAN | FND_USER_U1 | 1 |
    5 | 0 (0) | 00:00:01 |
    | 16 | TABLE ACCESS BY INDEX ROWID | PER_ALL_PEOPLE_F | 1 |
    31 | 3 (0) | 00:00:01 |
    |* 17 | INDEX RANGE SCAN | PER_PEOPLE_F_PK | 1 |
    | 2 (0) | 00:00:01 |
    |* 18 | INDEX RANGE SCAN | FND_USER_N1 | 1 |
    PLAN_TABLE_OUTPUT
    | 1 (0) | 00:00:01 |
    | 19 | TABLE ACCESS FULL | PO_AGENTS | 183 |
    2379 | 4 (0) | 00:00:01 |
    Predicate Information (identified by operation id):
    PLAN_TABLE_OUTPUT
    2 - filter(TO_DATE('01-JAN-08')<=TO_DATE('07-JAN-08'))
    3 - access("PH"."AGENT_ID"="POA"."AGENT_ID")
    8 - filter("AC1"."ACTION_CODE"='APPROVE' AND "AC1"."OBJECT_TYPE_CODE"='PO'AND
    TRUNC(INTERNAL_FUNCTION("AC1"."LAST_UPDATE_DATE"))>='01-JAN-08' AND
    TRUNC(INTERNAL_FUNCTION("AC1"."LAST_UPDATE_DATE"))<='07-JAN-08')
    10 - access("PH"."PO_HEADER_ID"="AC1"."OBJECT_ID")
    PLAN_TABLE_OUTPUT
    filter("SEQUENCE_NUM"= (SELECT MIN("AC2"."SEQUENCE_NUM") FROM "APPLSYS"."FND_USER"
    "FUSER2","PO"."PO_ACTION_HISTORY" "AC2" WHERE "AC2"."OBJECT_ID"=:B1 AND "AC2"."ACTION_CODE"='APPROVE'
    AND "AC2"."OBJECT_TYPE_CODE"='PO' AND "AC2"."LAST_UPDATED_BY"="FUSER2"."USER_ID"))
    13 - filter("AC2"."ACTION_CODE"='APPROVE' AND "AC2"."OBJECT_TYPE_CODE"='PO')
    14 - access("AC2"."OBJECT_ID"=:B1)
    PLAN_TABLE_OUTPUT
    15 - access("AC2"."LAST_UPDATED_BY"="FUSER2"."USER_ID")
    17 - access("PH"."AGENT_ID"="PERSON_ID" AND "EFFECTIVE_END_DATE">SYSDATE@!)
    filter("EFFECTIVE_END_DATE">SYSDATE@!)
    18 - access("PERSON_ID"="FUSER1"."EMPLOYEE_ID")
    Thanks

    Hi,
    any help for the above issue.

  • Sql statement for join tables

    hi there..i need ur helps
    Here are my tables n column name for each tables
    a) rep_arrngt
    Name
    REP_ARRNGT_ID
    REP_ARRNGT_DESC
    REP_ARRNGT_TYPE
    ACCT_CAT
    DEF_INDUSTRY_CODE
    MEDIA_ID
    LANGUAGE_ID
    CURRENCY
    PAGE_ID
    b) bci_rep_arrng
    Name
    REP_ARRNGT_ID
    BCI
    SUB_SUM_CODE
    DP_SUB_SUM_CODE
    c) acct_rep_arrngt_link
    Name
    ACCT_NO
    REP_ARRNGT_ID
    DOC_TYPE
    LAST_BILL_DATE
    BILL_FREQUENCY
    SCALING
    EFF_FROM_DATE
    EFF_TO_DATE
    MEDIA_ID
    Actually, i want to get the unique value for sub_sum_code according to the bci..
    i already use join tables n here is my sql statement :
    SELECT T1.SUB_SUM_CODE,T1.BCI,T1.REP_ARRNGT_ID,T2.REP_ARRNGT_ID,T3.REP_ARRNGT_ID FROM BCI_REP_ARRNG T1, REP_ARRNGT T2, ACCT_REP_ARRNGT_LINK T3 WHERE T1.REP_ARRNGT_ID=T2.REP_ARRNGT_ID AND T2.REP_ARRNGT_ID=T3.REP_ARRNGT_ID AND BCI='TTA00F06'
    n my results is :
    SUB_SUM_CODE BCI REP_ARRNGT_ID
    TBGSR TTA00F06 R1
    TBGSR TTA00F06 R1
    TBGSR TTA00F06 R1
    TBGSR TTA00F06 R1
    I get the repeated results for sub_sum_code..
    so, what i need to do if i want only 1 row results like this :
    [u]SUB_SUM_CODE BCI REP_ARRNGT_ID
    TBGSR TTA00F06 R1
    i try to use group by, but i get the error..plz help me

    If you only want "to get the unique value for sub_sum_code according to the bci" then why are you joining the tables in the first place? Not knowing PKs etc you could just use DISTINCT in your select statement.
    SELECT DISTINCT T1.SUB_SUM_CODE,
                    T1.BCI
    FROM BCI_REP_ARRNG T1
    AND BCI='TTA00F06'

  • Can any one please send me an update trigger (pl/sql procedure) for ap tables(ap_suppliers,ap_supplier_site_all,and contacts)

    Please send an query for update trigger for those tables .
         1: ap_suppliers
         2: ap_supplier_sites_all
         3: ap_supplier_contacts.
    Thanks,
    Chaitanya.

    Hi,
    Actually ID and Data are different names in my API. Here I mentioned like that.
    Am using Oracle 10g version.
    Yes I am going to get the multiple values using this Ref Cursor. The same ref cursor is used in another API of my package.
    In this API, the user actually enters Application_id and data. API should insert/update the version_master table with the inputs. See application_id is the foriegn key for app_master table.
    The requirement is whenever they enters application_id and data, if application_id already present in the version_master table, then the data should be updated and we should get a status flag for this using Out variable(i.e. using ref cursor only we are showing the status). if the application_id is not present in the version_master table, new record should be inserted. The sequence will generate the version_id for version_master table.
    But the Merge statement is working fine for update and insert also. Problem is am unable to see the success or failure through ref cursor. I don't know how exactly I can use this.
    If data is NULL the operation should be failed. i.e. I should get Failure status here. But am not getting this.
    Please remove the comments here and then check. If I use the NVL2 function I was able to get the status flag, i.e. S or F.
    OPEN resultset_o FOR
    SELECT NVL2 (data, 'S', 'F')
    FROM version_master
    WHERE application_id = application_id_i;
    1.How the value of data being not null will determine Success of the api and how null failure
    2.If the above select statement goes in to exception when others how I will no the failure
    I have to achieve the above scenarios.
    Please advice me.

  • Generating SQL Script for Existing Tables and DBs

    Hello,
    is it possible to generate automatically a SQL-Script from an existing table or oracle database ?
    I want to export an existing table from an Oracle DB (g11) if its possible with the data.
    Perhaps somebody could me explain how to to do this.
    I am using the "SQL Developer 2.1" and the "enterprise manager konsole".
    I'm a rookie in using this tools.
    Thank you for any informations.
    N. Wylutzki

    If you want to export data, you should use the export utility. This is documented:
    http://tinyurl.com/23b7on

  • How to create a DSN-less connection to SQL Server for linked tables in Access

    hey
    i cant understand how i use that Function
    if that information what you need
     stLocalTableName: dbo_user_name
    stRemoteTableName: user_name
    stServer :sedo2015.mssql.somee.com
    stDatabase :sedo2015
    stUsername :sedo_menf_SQLLogin_1
    stPassword :123456789
    how will be that Function??
    please write that Function to me
    '//Name : AttachDSNLessTable
    '//Purpose : Create a linked table to SQL Server without using a DSN
    '//Parameters
    '// stLocalTableName: Name of the table that you are creating in the current database
    '// stRemoteTableName: Name of the table that you are linking to on the SQL Server database
    '// stServer: Name of the SQL Server that you are linking to
    '// stDatabase: Name of the SQL Server database that you are linking to
    '// stUsername: Name of the SQL Server user who can connect to SQL Server, leave blank to use a Trusted Connection
    '// stPassword: SQL Server user password
    Function AttachDSNLessTable(stLocalTableName As String, stRemoteTableName As String, stServer As String, stDatabase As String, Optional stUsername As String, Optional stPassword As String)
    On Error GoTo AttachDSNLessTable_Err
    Dim td As TableDef
    Dim stConnect As String
    For Each td In CurrentDb.TableDefs
    If td.Name = stLocalTableName Then
    CurrentDb.TableDefs.Delete stLocalTableName
    End If
    Next
    If Len(stUsername) = 0 Then
    '//Use trusted authentication if stUsername is not supplied.
    stConnect = "ODBC;DRIVER=SQL Server;SERVER=" & stServer & ";DATABASE=" & stDatabase & ";Trusted_Connection=Yes"
    Else
    '//WARNING: This will save the username and the password with the linked table information.
    stConnect = "ODBC;DRIVER=SQL Server;SERVER=" & stServer & ";DATABASE=" & stDatabase & ";UID=" & stUsername & ";PWD=" & stPassword
    End If
    Set td = CurrentDb.CreateTableDef(stLocalTableName, dbAttachSavePWD, stRemoteTableName, stConnect)
    CurrentDb.TableDefs.Append td
    AttachDSNLessTable = True
    Exit Function
    AttachDSNLessTable_Err:
    AttachDSNLessTable = False
    MsgBox "AttachDSNLessTable encountered an unexpected error: " & Err.Description
    End Function

    thanks more thanks for you
    look i add that code in form
    it worked but i cant add recored  why ??
    Private Sub Form_Open(Cancel As Integer)
    Call AttachDSNLessTable("dbo_user_name", "user_name", "sedo2015.mssql.somee.com", "sedo2015", "sedo_menf_SQLLogin_1", "123456789")
    End Sub

  • Sql statement for a table name with a space in between

    Hi,
    I just noticed that one of my tables for Access is consisted of two word. It is called "CURRENT CPL". How would I put this table name into an sql statement. When I did what I normally do, it only reads the CURRENT and thinks that's the table name.
    Thanks
    Feng

    I just noticed that one of my tables for Access is
    consisted of two word. It is called "CURRENT CPL".
    How would I put this table name into an sql
    statement. When I did what I normally do, it only
    reads the CURRENT and thinks that's the table name.That is called a quoted identifier. The SQL (not java) for this would look like this....
    select "my field" from "CURRENT CPL"
    The double quote is the correct character to use. Note that quoted identifiers are case sensitive, normal SQL is not.

  • Sql access for large table

    hi,
    if a table has more than 6,000,000 records, any way to optimise to access so that can be faster.
    i try not to use sql statement alot. i try to manipulate data in internal table but first time i also need to have select statement to copy to internal table.
    any advice.
    thanks

    Tips
    1)in select include all primary keys in where condition to fetch data
    2)delare table without header line and with out occurs statement. and use work area to handle it
    Ex:-
    TYPES:BEGIN OF gty_kna1,                             " General Data in Customer Master
          kunnr TYPE kna1-kunnr,                         " Payer Number
          name1 TYPE kna1-name1,                                " Name1
          telf1 TYPE kna1-telf1,                         " Communication
          konzs TYPE kna1-konzs,                         " Corporate Group
          END OF gty_kna1.
    data:gs_kna1             TYPE gty_kna1,                             " General Data in Customer Master
    gt_kna1             TYPE TABLE OF gty_kna1,                    " General Data in Customer Master
    Note:
    •     In a SELECT statement, only the fields (field-list) which are needed are selected in the order that they reside on the database, thus network load is considerably less. The number of fields can be restricted in two ways using a field list in the SELECT clause of the statement or by using a view defined in ABAP/4 Dictionary.  The usage of view has the advantage of better reusability.
    •     SELECT SINGLE is used instead of SELECT-ENDSELECT loop when the entire key is available. SELECT SINGLE requires one communication with the database system, whereas SELECT-ENDSELECT needs two
    •     Always specify the conditions in the WHERE-clause instead of checking them with check-statements, the database system can then use an index (if possible) and the network load is considerably less.  You should not check the conditions with the CHECK statement because the contents of the whole table must be read from the database files into DBMS cache and transferred over the network. If the conditions are specified in the where clause DBMS reads exactly the needed data.
    •     Complex code is not embedded within a SELECT / ENDSELECT statement.
    •     No complex WHERE clauses, since complex where clauses are poison for the statement optimizer in any database system.
    •     For all frequently used SELECT statements, try to use an index. You always use an index if you specify (a generic part of) the index fields concatenated with logical ANDs in the Select statement's WHERE clause
    •     When loading data into Internal table, INTO TABLE OR APPENDING TABLE is used instead of a SELECT/APPEND combination. It is always faster to use the INTO TABLE version of a Select statement than to use APPEND statements.                      
    •     Use a select list with aggregate functions instead of checking and computing, when trying to find the maximum, minimum, sum and average value or the count of a database column.
    Rewards if useful...............
    Minal

  • SQL script for exporting table

    Could anyone please help me with SQL (plain SQL, not PL/SQL) for writing the data from a table into a .csv file?
    I need to run it on SQL developer. Can't use spool because it works only on SQL*PLus
    Edited by: user10403078 on Oct 15, 2008 2:24 AM

    But I want the SQL script to create a CSV file, because it should write the data from the tables into a CSV file, and proceed to delete it from the tables, every time the SQL script is run. I can't manually click and save.

  • SQL coding for partitioned tables

    Hi My tables are partitioned into 4 different partitions.. each one representing each quarter of a year.. do i need to specify the partition name in my sql query to grab the data or does oracle have the intelligence to go this partition based on my select statement..
    say q1, q2,q3,q4 table partitions and the table name is y1
    can i say
    <code> select * from y1 where date ='01/01/2005'</code>
    does this above written code takes you directly to the partition where this data is located..
    if it does how do we know that in the execution plan that it wasnot scanning the full table but rather one partition..
    thanks in advance

    have a look at the explain plan and you will see how oracle acces the partitioned table.
    All Oracle documentation can be found under
    http://otn.oracle.com/pls/db92/db92.docindex?remark=homepage
    You will probably find answer to your question under
    http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96524/toc.htm
    http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96533/toc.htm
    http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96520/toc.htm

  • Oracle equivalent for temp table variable

    Can anyone help me regarding this..
    sample code
    declare @temptable table (fldcaptioncode bigint, fldrownumber bigint identity (1,1))
    i have declaration in sqlserver stored procedure,
    Is there any equivalent in oracle 10g
    Thanks in advance
    Regards
    Ariff

    Ariff,
    temporary tables are supported by Oracle, and SQL Developer uses this feature.
    The DDL of the temporary table is extracted and generated as a standalone object.
    Please check docs, since there are several examples and informations about tem tables. Docs are available at
    http://download.oracle.com/docs/cd/E12151_01/index.htm
    or
    http://www.oracle.com/technology/tech/migration//workbench/index_sqldev_omwb.html
    Thanks
    Regards,
    MGILIBER

  • SQL query for join table and multiple values

    Trying to join two tables , Emphours and EmpStatus to get
    result which gives each emplyees hour 
    worked each day
    in past  say 1 year in what status. I need result similar to table 3 , Hours Can also be grouped per week
    all I need Is Each employees hours in each week and his status and position at that time if possible
    any help will be highly appreciated. Thank you 
    note: payday is every other Friday- week runs from Saturday through Friday
    EmpStatus Table tracks when employees status changed
    EmpHours
    employee
    workday
    payday
    hours
    position
    101
    1/1/2014
    1/3/2014
    8
    assistant
    101
    1/3/2014
    1/3/2014
    8
    assistant
    101
    1/4/2014
    1/17/2014
    8
    assistant
    101
    1/5/2014
    1/17/2014
    8
    assistant
    101
    1/7/2014
    1/17/2014
    8
    assistant
    101
    1/8/2014
    1/17/2014
    8
    assistant
    101
    1/9/2014
    1/17/2014
    8
    assistant
    101
    1/11/2014
    1/17/2014
    8
    assistant
    101
    1/13/2014
    1/17/2014
    8
    assistant
    101
    1/14/2014
    1/17/2014
    8
    assistant
    101
    1/18/2014
    2/14/2014
    8
    assistant
    102
    1/1/2014
    1/3/2014
    7
    manager
    102
    1/25/2014
    1/31/2014
    7
    manager
    102
    1/26/2014
    1/31/2014
    7
    manager
    102
    1/28/2014
    1/31/2014
    7
    manager
    102
    1/31/2014
    1/31/2014
    7
    manager
    103
    1/1/2014
    1/3/2014
    5
    intern
    103
    1/31/2014
    1/31/2014
    6
    intern
    104
    1/14/2014
    1/17/2014
    5
    supervisor
    104
    1/30/2014
    1/31/2014
    6
    supervisor
    EmpStatus
    employee
    start_date
    status
    101
    1/1/2014
    parttime
    101
    1/18/2014
    fulltime
    102
    1/1/2014
    seasonal
    102
    1/18/2014
    fulltime
    103
    1/1/2014
    partime
    103
    1/18/2014
    fulltime
    104
    1/4/2014
    parttime
    104
    1/18/2014
    fulltime
    Table 3
    employee
    status
    hours
    position
    workday
    weekend
    payday
    101
    parttime
    8
    assistant
    1/1/2014
    1/3/2014
    1/3/2014
    101
    parttime
    8
    assistant
    1/3/2014
    1/3/2014
    1/3/2014
    101
    parttime
    8
    assistant
    1/4/2014
    1/10/2014
    1/17/2014
    101
    parttime
    8
    assistant
    1/5/2014
    1/10/2014
    1/17/2014
    101
    parttime
    8
    assistant
    1/7/2014
    1/10/2014
    1/17/2014
    101
    parttime
    8
    assistant
    1/8/2014
    1/10/2014
    1/17/2014
    101
    parttime
    8
    assistant
    1/9/2014
    1/10/2014
    1/17/2014
    101
    parttime
    8
    assistant
    1/11/2014
    1/17/2014
    1/17/2014
    101
    parttime
    8
    assistant
    1/13/2014
    1/17/2014
    1/17/2014
    101
    parttime
    8
    assistant
    1/14/2014
    1/17/2014
    1/17/2014
    101
    fulltime
    8
    assistant
    1/18/2014
    1/24/2014
    2/14/2014
    102
    seasonal
    7
    manager
    1/1/2014
    1/3/2014
    1/3/2014
    102
    fulltime
    7
    manager
    1/25/2014
    1/25/2014
    2/14/2014
    102
    fulltime
    7
    manager
    1/26/2014
    1/26/2014
    2/14/2014
    102
    fulltime
    7
    manager
    1/28/2014
    1/28/2014
    2/14/2014
    102
    fulltime
    7
    manager
    1/31/2014
    1/31/2014
    2/14/2014
    103
    parttime
    5
    intern
    1/1/2014
    1/3/2014
    1/3/2014
    103
    fulltime
    6
    intern
    1/31/2014
    1/31/2014
    2/14/2014
    104
    parttime
    5
    supervisor
    1/14/2014
    1/17/2014
    1/17/2014
    104
    fulltime
    6
    supervisor
    1/30/2014
    1/31/2014
    1/31/2014

    Hello David,
    Try this query
    set dateformat mdy;
    declare @EmpHours table
    (Employee int,workday date,payday date,hours int,position varchar(50));
    insert into @EmpHours values
    (101,'1/1/2014','1/3/2014',8,'assistant'),
    (101,'1/3/2014','1/3/2014',8,'assistant'),
    (101,'1/4/2014','1/17/2014',8,'assistant'),
    (101,'1/5/2014','1/17/2014',8,'assistant'),
    (101,'1/7/2014','1/17/2014',8,'assistant'),
    (101,'1/8/2014','1/17/2014',8,'assistant'),
    (101,'1/9/2014','1/17/2014',8,'assistant'),
    (101,'1/11/2014','1/17/2014',8,'assistant'),
    (101,'1/13/2014','1/17/2014',8,'assistant'),
    (101,'1/14/2014','1/17/2014',8,'assistant'),
    (101,'1/18/2014','2/14/2014',8,'assistant'),
    (102,'1/1/2014','1/3/2014',7,'manager'),
    (102,'1/25/2014','1/31/2014',7,'manager'),
    (102,'1/26/2014','1/31/2014',7,'manager'),
    (102,'1/28/2014','1/31/2014',7,'manager'),
    (102,'1/31/2014','1/31/2014',7,'manager'),
    (103,'1/1/2014','1/3/2014',5,'intern'),
    (103,'1/31/2014','1/31/2014',6,'intern'),
    (104,'1/14/2014','1/17/2014',5,'supervisor'),
    (104,'1/30/2014','1/31/2014',6,'supervisor');
    --select * from @EmpHours
    declare @EmpStatus table
    (employee int,start_date date,status varchar(20));
    insert into @EmpStatus values
    (101,'1/1/2014','parttime'),
    (101,'1/18/2014','fulltime'),
    (102,'1/1/2014','seasonal'),
    (102,'1/18/2014','fulltime'),
    (103,'1/1/2014','partime'),
    (103,'1/18/2014','fulltime'),
    (104,'1/4/2014','parttime'),
    (104,'1/18/2014','fulltime');
    WITH C AS
    SELECT es.employee,es.start_date, es.status, ROW_NUMBER() OVER(partition by employee ORDER BY start_date) AS rownum
    FROM @EmpStatus ES
    CTE_RANGES as(
    SELECT cur.employee,Cur.start_date start_range, cur.status,case when nxt.start_date is null then '2099-12-31' else dateadd(d,-1,Nxt.start_date) end AS end_range
    FROM C AS Cur
    left JOIN C AS Nxt
    ON Nxt.rownum = Cur.rownum + 1 and cur.employee=nxt.employee)
    select eh.*,es.status from @EmpHours EH join CTE_RANGES Es on EH.Employee =es.employee and EH.workday between es.start_range and es.end_range
    --where es.employee=101
    You will need a calender table too which can be joined to the output of the above query to get the weekend dates.
    You can find the T-SQL code to generate the calender here
    http://stackoverflow.com/questions/19191577/t-sql-function-to-generate-calendar-table
    and posting the questions with necessary DDL , DML (like I have posted) would help us a lot. 
    Satheesh
    My Blog

  • How to use "Auto increment" in temp table Oracle

    Pleas tell me yaar,
    In MS Sql for Auto increment i am using like this "seqid int identity" for temp table
    t_seq_tbl table(seqid int identity,EVENT_SEQ_NO varchar(30))
    In oracle how to use....

    As far as I know there is not any auto increment data type in Oracle. Instead of this you should create a sequence and get the next value of the sequence while creating a row in your table.
    CREATE SEQUENCE Test_Sequence ;
    CREATE TABLE Test_Table ( Id NUMBER , Foo VARCHAR2(4) ) ;
    ALTER TABLE Test_Table ADD CONSTRAINT Test_Table_PK_Id PRIMARY KEY ( Id ) ;
    INSERT INTO Test_Table ( Id , Information ) VALUES ( Test_Sequence.NEXTVAL , 'FOO' ) ;

  • Temp tables in procedure

    Hi,
    I am trying to develop a procedure in which i have to create four tables to improve the performance of the procedure.
    is there any other way in which i can do this? i don't want to create four table objects. if i use global temporary table. then also it will create structure in DB. i tried with table of records method. that is getting too complicated since its a very big procedure.
    can anyone suggest me other ways of achieving this?

    user12288167 wrote:
    this procedure is called at the same time by 10 different interfaces. the procedure has 4 temp tables now, which are required to improve the performance. after all the processing is done it will insert the result into a final table. Temp tables are not required to improve performance. In fact, it slows things down and make performance worse.
    What db operation has the single largest performance impact? I/O.
    What does your so-called "+improvment+" do with temp tables? Generate more I/O for creating data in the temp tables and manipulate data in the temp tables.
    So, how can generating more I/O be a performance improvement??
    so we need separate tables for all these interfaces.i.e. 5*10=50 tables in all which is not acceptable by our project.
    or is there any way to implement wait in the procedure while it is being accessed somewhere else?You need to scrap that procedure entirely. It is pretty much junk and will perform like junk.
    There is very seldom a need for temp tables in Oracle. Very Important: The reasons for using temp tables in SQL-Server/Informix/etc DOES NOT exist in Oracle.
    In Oracle, readers of data NEVER blocks writers of data. And writers of data NEVER blocks readers of data. Oracle provides and guarantees read consistency. There is no need for temp tables to deal with the lack of data consistency or (unwarranted) read/write serialisation.
    Read up on Oracle read consistency - and use that, correctly. Without resorting to hacks like you had to do with temp tables in other (inferior) database products.

Maybe you are looking for

  • Best practices for Calling Multiple Business Services in OSB

    Hi All, I have a requirement where I need to call multiple business services in OSB. We are presently calling them sequentially in a proxy pipeline. I was wondering if we could accomplish the same task in a better way. Each of the business services a

  • LFPMG Field in Tcode : VT02N in Item overview tab

    Hi All, How to get LFPMG field in VT02N tcode item overview tab, in which table it is storing? Thanks, Madhan. Moderator message: please do some research before asking. Edited by: Thomas Zloch on Mar 3, 2011 2:43 PM

  • Wrong Button Name in Find/Change-Dialogue

    The button "Find/Change" in the Find/Change-Dialogue has a wrong name. Its behaviour is just the opposite: First it changes, then it searches again. The correct name can only be: "Change/Find". (This is part of the Wishlist already and published else

  • Weirdest Logic behavior (Deleting tracks will eat up RAM)

    Hi, I've been a Logic 9 user for quite a few years (4-5yrs at the least) and have never experienced anything like this. I'm currently working on a film project which requires using at least 25-30 Kontakt loaded tracks. My computer,  2.6Ghz i7 16gb Ra

  • URGENT - how do I convert and image from colour to black and white?

    Hi, I'm new to Java, and I really need some code to convert an image from colour to black and white! I would really appreciate any help, but since I don't know much about Java I would prefer some code or links to websites with the code. Thanks!!!