Need information on this Query

Hi guys,
can someone explain how this query works indetail.
SELECT DISTINCT (a.sal) FROM EMP A WHERE &N = (SELECT COUNT (DISTINCT (b.sal)) FROM EMP B WHERE a.sal<=b.sal);
Advance thanks for your help.
Kadiyala
Edited by: user10223931 on Mar 4, 2009 8:17 PM

Hi,
SELECT DISTINCT (a.sal),(SELECT COUNT (DISTINCT (b.sal)) FROM EMP B WHERE a.sal<=b.sal) FROM EMP A order by 2 descI hope this will help you.
The query will rank the records as per salary amount. and you will get the salary amount of the specified rank.

Similar Messages

  • Hello.  I just upgraded to Lion OS X 10.7.3.  I was previously running 10.5.7 which included the ENTOURAGE application.  how do I retrieve needed information from this application that no longer runs on this new system?

    Hello.  I just upgraded to Lion OS X 10.7.3.  I was previously running 10.5.7 which included the ENTOURAGE application.  how do I retrieve needed information from this application that no longer runs on this new system?

    The file you'll be looking for that has most of what you're looking for - messages, address book, etc. is the Entourage Database.  The verison of Microsoft Office I run (on Lion) is Office 2008.  By default the Entourage Database for this verison is at user/Documents/Microsoft User Data/Office 2008 Identities/Main Identity/Database.  That folder (Main Identitty) also has your rules, signatures, and such.  You'll have to recover this file from whatever backup you have.  If you have a different version of Entourage, the file location will be a little diffferent.
    Good luck
    srb

  • Please need help with this query

    Hi !
    Please need help with this query:
    Needs to show (in cases of more than 1 loan offer) the latest create_date one time.
    Meaning, In cases the USER_ID, LOAN_ID, CREATE_DATE are the same need to show only the latest, Thanks!!!
    select distinct a.id,
    create_date,
    a.loanid,
    a.rate,
    a.pays,
    a.gracetime,
    a.emailtosend,
    d.first_name,
    d.last_name,
    a.user_id
    from CLAL_LOANCALC_DET a,
    loan_Calculator b,
    bv_user_profile c,
    bv_mr_user_profile d
    where b.loanid = a.loanid
    and c.NET_USER_NO = a.resp_id
    and d.user_id = c.user_id
    and a.is_partner is null
    and a.create_date between
    TO_DATE('6/3/2008 01:00:00', 'DD/MM/YY HH24:MI:SS') and
    TO_DATE('27/3/2008 23:59:00', 'DD/MM/YY HH24:MI:SS')
    order by a.create_date

    Perhaps something like this...
    select id, create_date, loanid, rate, pays, gracetime, emailtosend, first_name, last_name, user_id
    from (
          select distinct a.id,
                          create_date,
                          a.loanid,
                          a.rate,
                          a.pays,
                          a.gracetime,
                          a.emailtosend,
                          d.first_name,
                          d.last_name,
                          a.user_id,
                          max(create_date) over (partition by a.user_id, a.loadid) as max_create_date
          from CLAL_LOANCALC_DET a,
               loan_Calculator b,
               bv_user_profile c,
               bv_mr_user_profile d
          where b.loanid = a.loanid
          and   c.NET_USER_NO = a.resp_id
          and   d.user_id = c.user_id
          and   a.is_partner is null
          and   a.create_date between
                TO_DATE('6/3/2008 01:00:00', 'DD/MM/YY HH24:MI:SS') and
                TO_DATE('27/3/2008 23:59:00', 'DD/MM/YY HH24:MI:SS')
    where create_date = max_create_date
    order by create_date

  • I need solution for this query

    hi all,
    could anyone please send me solution for this query these are the database tables am having
    TABLE NAME :USERS
    ATTRIBUTES
    UNAME
    PASSWORD
    GROUPNAME
    TABLE NAME:GROUPS
    ATTRIBUTES
    GROUPID
    GROUPNAME
    my requirement is that i need 2 acces the groupname of a particular user and the reamining groups to which i doesn't belong in A SINGLE QUERY
    my result needs to be like this
    Authorised group
    consultant
    UNAuthorised groups
    sales
    vender
    recruiter
    admin
    if any body got the solution please send

    hi All,
    I have 3 tables 1)PREVILEGES (groupname, previleges(values y or n only))
    2)GROUPS (groupid, groupname)
    3) USERS (uname, groupname).
    Here each user belongs to one group, each user hav a default previlege means example if user is consutant then he can access only consultant group. Means default previlege will be used. For default previleges, there is no record in Previleges table.
    The Problem is that, I need to reterive the groupname from users which de doesn't belong as well as his previleges from previleges, If there is no values in previleges in the table it should return n. or value what is therey.
    the different groups are
    SALES,CONSULTANT,VENDER,RECRUTER,ADMIN

  • Need help in this query using Case Statement

    I have the following query which is currently existing and I am adding few more conditions based on the new requirements which is based on a particular flag set as 1 or 0.
    If it is set to 1 then I should use the old query as it is and if it is set to 0 then I should add the new conditions.
    Basically when the flag is set to 0, I shouldnt be including some of the records that already exists and should include only new records. This is based on the plan_type_ids in (1,2,3,4).
    Hence I am using the Case statement to check if the plan_type_id is in (1,2) then do a set of not exists and if the plan_type_id in (3,4) then do set of not exists.
    But when I run this query it is giving me error. What am I doing wrong?
    Is there any other simple way to combine all the not exists for all of those select statements as given after the line ------------------------- into a single one?
    What am I doing wrong?
    I tried putting the NOT EXists before the case too but that too didnt work.
    Please help. Appreciate it.
    Thank you in advance.
    SELECT
    ee.employee_id
    ,'WELCOMEMSG'
    ,DECODE( me.member_enrollment_id
    ,first_enr.enrollment_id
    ,20
    ,23
    ) status_id
    ,me.member_enrollment_id
    ,wk.welcome_msg_id
    FROM wk
    ,employees ee
    ,MEMBER_ENROLLMENTS me
    ,plans pl
    ,( SELECT employee_id
    ,plan_type_id
    ,start_date
    ,plan_id
    ,MIN(MEMBER_ENROLLMENT_ID) member_enrollment_id
    FROM ( SELECT me.employee_id
    ,DECODE(pl.plan_type_id,1,2,pl.plan_type_id) plan_type_id
    ,pl.start_date
    ,wk.plan_id
    ,me.member_enrollment_id
    FROM wk
    ,PLANS pl
    ,MEMBER_ENROLLMENTS me
    WHERE wk.done_by = nvl('TEST' ,wk.done_by)
    AND wk.welcome_msg_name <> 'NONE'
    AND pl.employer_id = wk.employer_id
    AND wk.employer_id = 5
    AND DECODE(pl.plan_type_id,1,2,pl.plan_type_id) = wk.plan_type_id
    AND pl.plan_id = NVL(wk.plan_id,pl.plan_id)
    AND me.plan_id = pl.plan_id
    AND me.coverage_effective_date <> NVL(me.coverage_end_Date, me.coverage_effective_date + 1)
    AND me.coverage_effective_Date BETWEEN wk.start_date AND NVL(wk.end_date, me.coverage_effective_date + 1)
    MINUS
    SELECT me.employee_id
    ,DECODE(pl.plan_type_id,1,2,pl.plan_type_id) plan_type_id
    ,pl.start_date
    ,NULL plan_id
    ,me.member_enrollment_id
    FROM wk
    ,PLANS pl
    ,MEMBER_ENROLLMENTS me
    WHERE wk.done_by = nvl(NULL,wk.done_by)
    AND wk.welcome_msg_name <> 'NONE'
    AND pl.employer_id = wk.employer_id
    AND wk.employer_id = 5
    AND DECODE(pl.plan_type_id,1,2,pl.plan_type_id) = wk.plan_type_id
    AND pl.plan_id = wk.plan_id
    AND me.plan_id = pl.plan_id
    AND me.coverage_effective_date <> NVL(me.coverage_end_Date, me.coverage_effective_date + 1)
    AND me.coverage_effective_Date BETWEEN wk.start_date AND NVL(wk.end_date, me.coverage_effective_date + 1)
    WHERE employee_id = 100
    GROUP BY employee_id ,plan_type_id,start_date ,plan_id
    )first_enr
    ,MEMBER_EVENTS mv
    WHERE wk.done_by = nvl(NULL,wk.done_by)
    AND wk.employer_id = ee.employer_id
    AND ee.employee_id = me.employee_id
    AND ee.employee_id = 100
    AND me.plan_id = pl.plan_id
    AND me.coverage_effective_date <> NVL(me.coverage_end_Date, me.coverage_effective_date + 1)
    AND me.coverage_effective_Date BETWEEN wk.start_date AND NVL(wk.end_date, me.coverage_effective_date + 1)
    AND is_expired(me.employee_id,me.plan_id) = 'Y'
    AND DECODE(pl.plan_type_id,1,2,pl.plan_type_id) = wk.plan_type_id
    AND pl.plan_id=nvl(wk.plan_id,pl.plan_id)
    AND me.employee_id = first_enr.employee_id
    AND DECODE(pl.plan_type_id,1,2,pl.plan_type_id) = first_enr.plan_type_id
    AND pl.start_date = first_enr.start_date
    AND me.member_enrollment_id = mv.member_enrollment_id (+)
    AND 'WELCOMEMSG' = mv.event_name(+)
    AND mv.member_enrollment_id IS NULL
    AND wk.welcome_msg_name <> 'NONE'
    AND NVL(first_enr.plan_id,0) = NVL( wk.plan_id,0)
    AND (FN_get_all_participant(wk.employer_id) = 1
    OR
    (FN_get_all_participant(wk.employer_id) = 0
    AND (CASE WHEN pl.plan_type_id IN (1,2)
    THEN NOT EXISTS (SELECT 'X'
    FROM member_accounts ma
    member_enrollments men3
    plans pl3
    plan_types pt3
    WHERE ma.member_account_id = men3.member_account_id
    AND ma.employee_id = me.employee_id
    AND ma.plan_id = pl3.plan_id
    AND pl3.start_date < pl.START_DATE
    AND TRUNC(men3.coverage_effective_date) <> TRUNC(NVL(men3.coverage_end_date, men3.coverage_effective_date + 1 ))
    AND pl3.plan_type_id = pt3.plan_type_id
    AND pt3.plan_type_id in (1, 2)
    UNION
    (SELECT 'X'
    FROM member_accounts ma
    member_enrollments men3
    plans pl3
    plan_types pt3
    WHERE ma.member_account_id = men3.member_account_id
    AND ma.employee_id = me.employee_id
    AND ma.plan_id = pl3.plan_id
    AND pl3.start_date = (pl.start_date - 365)
    \ AND TRUNC(men3.coverage_effective_date) <> TRUNC(NVL(men3.coverage_end_date, men3.coverage_effective_date + 1 ))
    AND pl3.plan_type_id = pt3.plan_type_id
    AND pt3.plan_type_id = wk.plan_type_id
    UNION
    (SELECT 'X'
    FROM member_accounts ma
    member_enrollments men3
    plans pl3
    plan_types pt3
    WHERE ma.member_account_id = men3.member_account_id
    AND ma.employee_id = men2.employee_id
    AND ma.plan_id = pl3.plan_id
    AND pl3.start_date < pl2.START_DATE -- '01-Jan-2011'
    AND TRUNC(men3.coverage_effective_date) <> TRUNC(NVL(men3.coverage_end_date, men3.coverage_effective_date + 1 ))
    AND pl3.plan_type_id = pt3.plan_type_id
    AND pt3.plan_type_id = 2
    UNION
    (SELECT 'X'
    FROM member_accounts ma
    member_enrollments men3
    plans pl3
    plan_types pt3
    WHERE ma.member_account_id = men3.member_account_id
    AND ma.employee_id = men2.employee_id
    AND ma.plan_id = pl3.plan_id
    AND pl3.start_date < pl2.START_DATE -- '01-Jan-2011'
    AND TRUNC(men3.coverage_effective_date) <> TRUNC(NVL(men3.coverage_end_date, men3.coverage_effective_date + 1 ))
    AND pl3.plan_type_id = pt3.plan_type_id
    AND pt3.plan_type_id = 1
    WHEN pl.plan_type_id IN (3, 4)
    THEN NOT EXISTS (SELECT 'X'
    FROM member_accounts ma
    member_enrollments men3
    plans pl3
    plan_types pt3
    WHERE ma.member_account_id = men3.member_account_id
    AND ma.employee_id = men2.employee_id
    AND nvl(ma.account_end_date, sysdate) <= trunc(sysdate)
    AND ma.plan_id = pl3.plan_id
    AND pl3.start_date <= pl2.START_DATE
    AND TRUNC(men3.coverage_effective_date) <> TRUNC(NVL(men3.coverage_end_date, men3.coverage_effective_date + 1 ))
    AND pl3.plan_type_id = pt3.plan_type_id
    AND pt3.plan_type_id in (3, 4)
    END
    AND (CASE WHEN pl.plan_type_id IN (1,2)
    ERROR at line 89:
    ORA-00936: missing expression

    Maybe
    SELECT ee.employee_id,
           'WELCOMEMSG',
           DECODE(me.member_enrollment_id,first_enr.enrollment_id,20,23) status_id,
           me.member_enrollment_id,
           wk.welcome_msg_id
      FROM wk,
           employees ee,
           MEMBER_ENROLLMENTS me,
           plans pl,
           (SELECT employee_id,
                   plan_type_id,
                   start_date,
                   plan_id,
                   MIN(MEMBER_ENROLLMENT_ID) member_enrollment_id
              FROM (SELECT me.employee_id,
                           DECODE(pl.plan_type_id,1,2,pl.plan_type_id) plan_type_id,
                           pl.start_date,
                           wk.plan_id,
                           me.member_enrollment_id
                      FROM wk,
                           PLANS pl,
                           MEMBER_ENROLLMENTS me
                     WHERE wk.done_by = nvl('TEST',wk.done_by)  /* same as wk.done_by = 'TEST' */
                       AND wk.welcome_msg_name 'NONE'
                       AND pl.employer_id = wk.employer_id
                       AND wk.employer_id = 5
                       AND DECODE(pl.plan_type_id,1,2,pl.plan_type_id) = wk.plan_type_id
                       AND pl.plan_id = NVL(wk.plan_id,pl.plan_id)
                       AND me.plan_id = pl.plan_id
                       AND me.coverage_effective_date != NVL(me.coverage_end_Date,me.coverage_effective_date + 1)
                       AND me.coverage_effective_Date BETWEEN wk.start_date AND NVL(wk.end_date,me.coverage_effective_date + 1)
                    MINUS
                    SELECT me.employee_id,
                           DECODE(pl.plan_type_id,1,2,pl.plan_type_id) plan_type_id,
                           pl.start_date,
                           NULL plan_id,
                           me.member_enrollment_id
                      FROM wk,
                           PLANS pl,
                           MEMBER_ENROLLMENTS me
                     WHERE wk.done_by = nvl(NULL,wk.done_by)  /* same as 1 = 1 */
                       AND wk.welcome_msg_name 'NONE'
                       AND pl.employer_id = wk.employer_id
                       AND wk.employer_id = 5
                       AND DECODE(pl.plan_type_id,1,2,pl.plan_type_id) = wk.plan_type_id
                       AND pl.plan_id = wk.plan_id
                       AND me.plan_id = pl.plan_id
                       AND me.coverage_effective_date NVL(me.coverage_end_Date,me.coverage_effective_date + 1)
                       AND me.coverage_effective_Date BETWEEN wk.start_date AND NVL(wk.end_date, me.coverage_effective_date + 1)
             WHERE employee_id = 100
             GROUP BY employee_id,
                      plan_type_id,
                      start_date,
                      plan_id
           ) first_enr,
           MEMBER_EVENTS mv
    WHERE wk.done_by = nvl(NULL,wk.done_by)
       AND wk.employer_id = ee.employer_id
       AND ee.employee_id = me.employee_id
       AND ee.employee_id = 100
       AND me.plan_id = pl.plan_id
       AND me.coverage_effective_date != NVL(me.coverage_end_Date,me.coverage_effective_date + 1)
       AND me.coverage_effective_Date BETWEEN wk.start_date AND NVL(wk.end_date, me.coverage_effective_date + 1)
       AND is_expired(me.employee_id,me.plan_id) = 'Y'
       AND DECODE(pl.plan_type_id,1,2,pl.plan_type_id) = wk.plan_type_id
       AND pl.plan_id = nvl(wk.plan_id,pl.plan_id)
       AND me.employee_id = first_enr.employee_id
       AND DECODE(pl.plan_type_id,1,2,pl.plan_type_id) = first_enr.plan_type_id
       AND pl.start_date = first_enr.start_date
       AND me.member_enrollment_id = mv.member_enrollment_id(+)
       AND 'WELCOMEMSG' = mv.event_name(+)
       AND mv.member_enrollment_id IS NULL
       AND wk.welcome_msg_name != 'NONE'
       AND NVL(first_enr.plan_id,0) = NVL(wk.plan_id,0)
       AND (
            FN_get_all_participant(wk.employer_id) = 1
        OR
            (FN_get_all_participant(wk.employer_id) = 0
       AND   NOT EXISTS(SELECT 'X'
                          FROM member_accounts ma,
                               member_enrollments men3,
                               plans pl3,
                               plan_types pt3
                         WHERE ma.member_account_id = men3.member_account_id
                           AND ma.employee_id = me.employee_id
                           AND ma.plan_id = pl3.plan_id
                           AND pl3.start_date < pl.START_DATE
                           AND TRUNC(men3.coverage_effective_date) != TRUNC(NVL(men3.coverage_end_date,men3.coverage_effective_date + 1))
                           AND pl3.plan_type_id = pt3.plan_type_id
                           AND pt3.plan_type_id in (1,2)
                           and pl.plan_type_id IN (1,2)
                        UNION
                        SELECT 'X'
                          FROM member_accounts ma,
                               member_enrollments men3,
                               plans pl3,
                               plan_types pt3
                         WHERE ma.member_account_id = men3.member_account_id
                           AND ma.employee_id = me.employee_id
                           AND ma.plan_id = pl3.plan_id
                           AND pl3.start_date = (pl.start_date - 365)
                           AND TRUNC(men3.coverage_effective_date) != TRUNC(NVL(men3.coverage_end_date,men3.coverage_effective_date + 1))
                           AND pl3.plan_type_id = pt3.plan_type_id
                           AND pt3.plan_type_id = wk.plan_type_id
                           and pl.plan_type_id IN (1,2)
                        UNION
                        SELECT 'X'
                          FROM member_accounts ma,
                               member_enrollments men3,
                               plans pl3,
                               plan_types pt3
                         WHERE ma.member_account_id = men3.member_account_id
                           AND ma.employee_id = men2.employee_id
                           AND ma.plan_id = pl3.plan_id
                           AND pl3.start_date < pl2.START_DATE -- '01-Jan-2011'
                           AND TRUNC(men3.coverage_effective_date) != TRUNC(NVL(men3.coverage_end_date,men3.coverage_effective_date + 1))
                           AND pl3.plan_type_id = pt3.plan_type_id
                           AND pt3.plan_type_id = (1,2)
                           and pl.plan_type_id IN (1,2)
                        UNION
                        SELECT 'X'
                          FROM member_accounts ma,
                               member_enrollments men3,
                               plans pl3,
                               plan_types pt3
                         WHERE ma.member_account_id = men3.member_account_id
                           AND ma.employee_id = men2.employee_id
                           AND trunc(nvl(ma.account_end_date,sysdate)) <= trunc(sysdate)
                           AND ma.plan_id = pl3.plan_id
                           AND pl3.start_date <= pl2.START_DATE
                           AND TRUNC(men3.coverage_effective_date) != TRUNC(NVL(men3.coverage_end_date,men3.coverage_effective_date + 1))
                           AND pl3.plan_type_id = pt3.plan_type_id
                           AND pt3.plan_type_id in (3,4)
                           and pl.plan_type_id IN (3,4)
           )Regards
    Etbin

  • Need to tune this query

    Hi
    I dont know anything about tuning
    can anybody help to tune this query
    SQL> set autotrace traceonly explain
    SQL> select count(*) from ibs_x_t_receipts c
      2  where exists                          
      3  (Select 1 from ibs_s_i_doc_receipt a,ibs_x_t_bill b
      4   where A.app_fr_doc_no = c.receipt_no
      5     and a.app_to_doc_no = b.doc_no
      6     and a.app_to_tr_type = 'TRN001'
      7     and A.app_fr_tr_type = 'TRN002'
      8     and b.bill_month <= '31-dec-2008'
      9     and b.balance_ser_amt = 0
    10     and b.balance_tax_amt = 0)
    11  /
    Execution Plan
       0      SELECT STATEMENT Optimizer=ALL_ROWS (Cost=212880 Card=1 Byte
              s=21)
       1    0   SORT (AGGREGATE)
       2    1     NESTED LOOPS (Cost=212880 Card=1 Bytes=21)
       3    2       VIEW OF 'VW_SQ_1' (VIEW) (Cost=212878 Card=1 Bytes=14)
       4    3         HASH (UNIQUE)
       5    4           NESTED LOOPS
       6    5             NESTED LOOPS (Cost=212878 Card=1 Bytes=66)
       7    6               VIEW OF 'index$_join$_002' (VIEW) (Cost=30021
              Card=91387 Bytes=3564093)
       8    7                 HASH JOIN
       9    8                   INDEX (RANGE SCAN) OF 'SIDOC_INDX1' (INDEX
              ) (Cost=171215 Card=91387 Bytes=3564093)
      10    8                   INDEX (RANGE SCAN) OF 'SIDOC_INDX2' (INDEX
              ) (Cost=366130 Card=91387 Bytes=3564093)
      11    6               INDEX (UNIQUE SCAN) OF 'ITL_PK2' (INDEX (UNIQU
              E)) (Cost=1 Card=1)
      12    5             TABLE ACCESS (BY INDEX ROWID) OF 'IBS_X_T_BILL'
              (TABLE) (Cost=2 Card=1 Bytes=27)
      13    2       INDEX (UNIQUE SCAN) OF 'RECEIPTS_PK2' (INDEX (UNIQUE))
               (Cost=1 Card=1 Bytes=7)it is running like anything, i didn't get the result.
    Please help me
    kanish

    --untested
    SELECT COUNT (*)
      FROM ibs_x_t_receipts c
    WHERE EXISTS (
              SELECT 1
                FROM ibs_s_i_doc_receipt a
               WHERE a.app_fr_doc_no = c.receipt_no
                 AND a.app_to_tr_type = 'TRN001'
                 AND a.app_fr_tr_type = 'TRN002'
                 AND EXISTS (
                        SELECT 1
                          FROM ibs_x_t_bill b
                         WHERE a.app_to_doc_no = b.doc_no
                           AND b.bill_month <= '31-dec-2008'
                           AND b.balance_ser_amt = 0
                           AND b.balance_tax_amt = 0))regards,
    friend
    Edited by: most wanted!!!! on Apr 17, 2012 3:51 AM

  • Need Information on af:query component

    Hi,
    I need some information on the <af:query> component in JDev 11g.
    When using ADF 11g's new component, ADF Query (af:query) whether the default "All Queryable Attributes" or on other newly defined View Criterias:
    1     What are the disadvantages of this component, given that the result-set - without filtering - is large (between 1350 and 1700 rows, approximately).
    2     Does it fetch all rows from the database, then performs filtering upon user's entered search criteria – i.e., hitting the "search" button?
    3     Is there a way to add client-side validation on the search criteria attributes?
    4     In general: What is the best practice to implement a Search Form in ADF 11g
    Kindly provide your inputs for the same.
    Thanks,
    Vineet

    user445872 wrote:
    Hi,
    I need some information on the <af:query> component in JDev 11g.
    When using ADF 11g's new component, ADF Query (af:query) whether the default "All Queryable Attributes" or on other newly defined View Criterias:
    1     What are the disadvantages of this component, given that the result-set - without filtering - is large (between 1350 and 1700 rows, approximately).
    2     Does it fetch all rows from the database, then performs filtering upon user's entered search criteria – i.e., hitting the "search" button? You could tune your VO not to exeute the query by default (i.e., before applying a search criteria)
    check this blog for sample: http://andrejusb-samples.blogspot.com/2009/08/jdevadf-sample-oracle-adf-tuning.html
    As an other option, you could have a default view criteria applied and executed to filter to result set if it is applicable for your usecase.
    3     Is there a way to add client-side validation on the search criteria attributes?I'm not sure about this though.
    4     In general: What is the best practice to implement a Search Form in ADF 11g
    In addition check this sample as well. It might be of help: http://andrejusb-samples.blogspot.com/2009/09/jdevadf-sample-programmatical-reset-for.html
    regards,
    ~K

  • Help needed in tuning this query

    This is the SQL i would like to tune for performace...
    The table structure is given below.
    The table has about 2 million rows.
    From the second day onwards only around 10% of records will be between Load_Start_Time and Load_End_Time. Among these around 50% will have THAMES_URN_WITH_ROLE_SUFFIX as 'TP%'. At present there are unique and primary key indexes on THAMES_URN_WITH_ROLE_SUFFIX .
    I'm sure that we need a b-tree index on STG_UPDATE_DATE_TIME as it is the column with good selectivity.
    I'm primarily concerned about the substr, instr and reverese on THAMES_URN_WITH_ROLE_SUFFIX.
    Also pls. let me know if the order of predicates is right.
    Thanks in advance.
    SELECT TPD_STG_TL_SF_LEGAL_OWNER.THAMES_URN, TPD_STG_TL_SF_LEGAL_OWNER.UPDATE_SOURCE, TPD_STG_TL_SF_LEGAL_OWNER.SOURCE_EXTRACT_DATE_TIME, TPD_STG_TL_SF_LEGAL_OWNER.LEGAL_OWNERSHIP_ISSUE_IND, TPD_STG_TL_SF_LEGAL_OWNER.CONTACTABLE_INDICATOR, TPD_STG_TL_SF_LEGAL_OWNER.ADMIN_CONTROL_INDICATOR, TPD_STG_TL_SF_LEGAL_OWNER.BANKRUPTCY_INDICATOR, TPD_STG_TL_SF_LEGAL_OWNER.ASSIGNED_INDICATOR, TPD_STG_TL_SF_LEGAL_OWNER.IN_TRUST_INDICATOR, TPD_STG_TL_SF_LEGAL_OWNER.DIVORCE_CASE_INDICATOR, TPD_STG_TL_SF_LEGAL_OWNER.POA_COP_INDICATOR, TPD_STG_TL_SF_LEGAL_OWNER.CLEANSING_STATUS, TPD_STG_TL_SF_LEGAL_OWNER.CATEGORY
    FROM
    TPD_STG_TL_SF_LEGAL_OWNER
    WHERE
    ((TPD_STG_TL_SF_LEGAL_OWNER.STG_UPDATE_DATE_TIME > '$$Load_Start_Time'
    AND
    TPD_STG_TL_SF_LEGAL_OWNER.STG_UPDATE_DATE_TIME <= '$$Load_End_Time')
    OR
    (TPD_STG_TL_SF_LEGAL_OWNER.TPDB_PROCESSED_IDENTIFIER != 'Y') )
    AND
    SUBSTR(TPD_STG_TL_SF_LEGAL_OWNER.THAMES_URN_WITH_ROLE_SUFFIX,1,2)='TP'
    AND
    SUBSTR(REVERSE( TPD_STG_TL_SF_LEGAL_OWNER.THAMES_URN_WITH_ROLE_SUFFIX),INSTR(REVERSE( TPD_STG_TL_SF_LEGAL_OWNER.THAMES_URN_WITH_ROLE_SUFFIX),'-',1)-1,1)!='S'
    ========================================
    CREATE TABLE TPD_STG_TL_SF_LEGAL_OWNER
    THAMES_URN VARCHAR2(35 BYTE) NOT NULL,
    UPDATE_SOURCE VARCHAR2(3 BYTE),
    SOURCE_EXTRACT_DATE_TIME DATE,
    LEGAL_OWNERSHIP_ISSUE_IND CHAR(1 BYTE),
    CONTACTABLE_INDICATOR CHAR(1 BYTE),
    ADMIN_CONTROL_INDICATOR CHAR(1 BYTE),
    BANKRUPTCY_INDICATOR CHAR(1 BYTE),
    ASSIGNED_INDICATOR CHAR(1 BYTE),
    IN_TRUST_INDICATOR CHAR(1 BYTE),
    DIVORCE_CASE_INDICATOR CHAR(1 BYTE),
    POA_COP_INDICATOR CHAR(1 BYTE),
    THAMES_URN_WITH_ROLE_SUFFIX VARCHAR2(39 BYTE),
    THAMES_LEGAL_OWNERSHIP_IND CHAR(1 BYTE),
    PRODUCT_HOLDING_ROLE_TYPE VARCHAR2(21 BYTE),
    OWNERSHIP_SPLIT_PERCENTAGE NUMBER(3),
    SOURCE_SYSTEM VARCHAR2(3 BYTE),
    TITLE VARCHAR2(50 BYTE),
    FIRST_NAME VARCHAR2(50 BYTE),
    MIDDLE_INITIAL VARCHAR2(50 BYTE),
    SURNAME VARCHAR2(50 BYTE),
    GENDER CHAR(1 BYTE),
    BIRTH_DATE DATE,
    DEATH_INDICATOR CHAR(1 BYTE),
    DEATH_RECORD_DATE DATE,
    NATIONAL_INSURANCE_NUMBER VARCHAR2(9 BYTE),
    GONE_AWAY_INDICATOR CHAR(1 BYTE),
    ADDRESS_LINE_1 VARCHAR2(50 BYTE),
    ADDRESS_LINE_2 VARCHAR2(50 BYTE),
    ADDRESS_LINE_3 VARCHAR2(50 BYTE),
    ADDRESS_LINE_4 VARCHAR2(50 BYTE),
    ADDRESS_LINE_5 VARCHAR2(50 BYTE),
    POST_CODE VARCHAR2(12 BYTE),
    COUNTRY VARCHAR2(50 BYTE),
    OVERSEAS_ADDRESS_INDICATOR CHAR(1 BYTE),
    ORGANISATION_NAME VARCHAR2(50 BYTE),
    TPDB_PROCESSED_IDENTIFIER CHAR(2 BYTE),
    CLEANSING_STATUS VARCHAR2(30 BYTE),
    CATEGORY VARCHAR2(50 BYTE),
    SCHEME_NAME VARCHAR2(50 BYTE),
    STG_CREATE_DATE_TIME DATE,
    STG_UPDATE_DATE_TIME DATE,
    LAST_UPDATED_DATE_TIME DATE
    TABLESPACE TPDBS01A_DATA
    PCTUSED 0
    PCTFREE 10
    INITRANS 1
    MAXTRANS 255
    STORAGE (
    INITIAL 128K
    NEXT 128K
    MINEXTENTS 1
    MAXEXTENTS 2147483645
    PCTINCREASE 0
    BUFFER_POOL DEFAULT
    LOGGING
    NOCOMPRESS
    NOCACHE
    NOPARALLEL
    MONITORING;
    CREATE UNIQUE INDEX TPD_STG_TL_SF_LEGAL_OWNER_PK ON TPD_STG_TL_SF_LEGAL_OWNER
    (THAMES_URN_WITH_ROLE_SUFFIX)
    LOGGING
    TABLESPACE TPDBS01A_DATA
    PCTFREE 10
    INITRANS 2
    MAXTRANS 255
    STORAGE (
    INITIAL 128K
    NEXT 128K
    MINEXTENTS 1
    MAXEXTENTS 2147483645
    PCTINCREASE 0
    BUFFER_POOL DEFAULT
    NOPARALLEL;
    ALTER TABLE TPD_STG_TL_SF_LEGAL_OWNER ADD (
    CONSTRAINT TPD_STG_TL_SF_LEGAL_OWNER_PK
    PRIMARY KEY
    (THAMES_URN_WITH_ROLE_SUFFIX)
    USING INDEX
    TABLESPACE TPDBS01A_DATA
    PCTFREE 10
    INITRANS 2
    MAXTRANS 255
    STORAGE (
    INITIAL 128K
    NEXT 128K
    MINEXTENTS 1
    MAXEXTENTS 2147483645
    PCTINCREASE 0
    ));

    > If indexes don't help, is the only way to gain REAL
    performance gain on this type of query is to
    partition the table
    If a Full Table Scan on a table takes "too long" (and
    this is purely subjective - "too long" is different
    for every problem) and indexes can't help, and we
    need <100% of the rows, and if partitioning will give
    us the performance we desire, is it OK do it ? Also
    would STG_UPDATE_DATE_TIME be the best column to do a
    index partion ?
    For this type of query, partitioning on STG_UPDATE_DATE_TIME would be good.
    However, partitioning is not done just for one query. It has to fit in your total design. For example, if you are also doing queries with a predicate like <column with a local unique index but not the partition key> = <constant>, it would have to visit all partitions instead of just one, and those queries would take much longer to execute. You can make the index global, but there all kind of maintenance issues with that. In short: be careful about partitioning and think it through first.
    > But is it a good option to partition tables with
    total no. of rows between 2 million and 5 million ? I
    thought partitioning is better done for tables > 20
    million.
    Please throw some light on that.
    Generally, partitioning is done on bigger tables, yes. But it is not about some specific number of rows. You partition a table when all forecasted use of the table is known, so you can make a good judgement which usages will benefit, which ones won't be affected and which ones are likely to suffer. When the benefits outweigh the disadvantages, you partition...
    Above I had an example about queries that are going to suffer. Partitioning is beneficial for example when once in some period you'd have to delete A LOT of old rows. Or when you have some data warehousing queries that need like 10% of only the most recent data in a huge table.
    The decision is yours.
    Regards,
    Rob.

  • Need help on this query

    hi ,
    I have the following data and the expected results.
    Have managed to return the results in a procedure but the performance is not good.
    Could a analytic be used instead ? need advise
    logic
    1. if all type is of run then i'll simply get the id and its seq
    2. however , if the type is a if ...else then i'll need to check against table B and whether passing the if else will determine the seq to be used and if it passes the if then it'll go to the next id, if not if will go the else until it reaches the end of that section of if .. else for the same id before going to the next id
    table A
    id     seq     type          checkname     checkvalue     check          fail          nextseq     
    id0     1     run     
    id0     2     run
    id0     3     run
    id1     1     if          ac          5          =          3          
    id1     2     run                                                  end
    id1     3     elseif          ac          6          >=          4          
    id1     4     run
    id1     5     else                                                  end          
    id1     6     run          
    id2     1     run
    id2     2     run
    id2     3     if          an          5          <=          5
    id2     4     run
    id2     5     else                                                  end     
    id2     6     run
    scenario 1
    table B
    id     checkname     val
    id0     aa          0
    id1     ac          2
    id1     ab          8
    id2     ab          4
    id     an          5
    RESULTS :
    id     seq     
    id0     1
    id0     2
    id0     3
    id1     6
    id2     1
    id2     2
    id2     4
    scenario 2
    table B
    id     checkname     val
    id0     aa          0
    id1     ac          5
    id1     ab          8
    id2     ab          4
    id     an          6
    RESULTS :
    id     seq     
    id0     1
    id0     2
    id0     3
    id1     2
    id2     1
    id2     2
    id2     6appreciate ur advise
    tks & rgds

    ok,
    of course you can do it with model
    but still it can be done with analytic functions.
    one more question
    what is the condition to be checked?
    a.checkvalue || a.check || b.val
    or
    b.val || a.check || a.checkvalue
    accroding to your OP it seems the second choise is correct, isn't it?
    SQL> -- first scenario
    SQL>
    SQL> with tableA as (select 'id0' id, 1 seq, 'run' type, null checkname, null checkvalue, null check_, null fail, null nextseq from dual union all
      2                   select 'id0',    2,   'run',       null,null,null,null,null from dual union all
      3                   select 'id0',    3,   'run',       null,null,null,null,null from dual union all
      4                   select 'id1',    1,   'if',        'ac',5,'=',3,null from dual union all
      5                   select 'id1',    2,   'run',       null,null,null,null,'end' from dual union all
      6                   select 'id1',    3,   'elseif',    'ac',6,'>=',4,null from dual union all
      7                   select 'id1',    4,   'run',       null,null,null,null,null from dual union all
      8                   select 'id1',    5,   'else',      null,null,null,null,'end' from dual union all
      9                   select 'id1',    6,   'run',       null,null,null,null,null from dual union all
    10                   select 'id2',    1,   'run',       null,null,null,null,null from dual union all
    11                   select 'id2',    2,   'run',       null,null,null,null,null from dual union all
    12                   select 'id2',    3,   'if',        'an',5,'<=',5,null from dual union all
    13                   select 'id2',    4,   'run',       null,null,null,null,null from dual union all
    14                   select 'id2',    5,   'else',      null,null,null,null,'end' from dual union all
    15                   select 'id2',    6,   'run',       null,null,null,null,null from dual),
    16  tableB as (select 'id0' id, 'aa' checkname, 0 val from dual union all
    17             select 'id1', 'ac', 2 from dual union all
    18             select 'id1', 'ab', 8 from dual union all
    19             select 'id2', 'ab', 4 from dual union all
    20             select 'id2', 'an', 5 from dual)
    21             --
    22             select id, seq from (select tt.*, first_value(decode(flag,1,seq) ignore nulls) over (partition by id order by seq) FV from
    23             (select a.*, b.val, lag(nvl(nvl2(val,case check_ when '='  then decode(sign(val-checkvalue),0,1,0)
    24                                          when '>=' then decode(sign(val-checkvalue),-1,0,1)
    25                                          when '>'  then decode(sign(val-checkvalue),1,1,0)
    26                                          when '<=' then decode(sign(val-checkvalue),1,0,1)
    27                                          when '<'  then decode(sign(val-checkvalue),-1,1,0)
    28                                     end, decode(type,'else',1)),val)) over (partition by a.id order by seq)  flag, lag(type,1,type) over (partition by a.id order by seq) lag_type
    29                              from tableA a, tableB b
    30              where a.id=b.id(+)
    31                and a.checkname=b.checkname(+)
    32                order by 1,2) tt
    33  ) where (type='run' and lag_type='run') or seq=FV
    34  /
    ID         SEQ
    id0          1
    id0          2
    id0          3
    id1          6
    id2          1
    id2          2
    id2          4
    7 rows selected
    SQL> --second scenario
    SQL>
    SQL> with tableA as (select 'id0' id, 1 seq, 'run' type, null checkname, null checkvalue, null check_, null fail, null nextseq from dual union all
      2                   select 'id0',    2,   'run',       null,null,null,null,null from dual union all
      3                   select 'id0',    3,   'run',       null,null,null,null,null from dual union all
      4                   select 'id1',    1,   'if',        'ac',5,'=',3,null from dual union all
      5                   select 'id1',    2,   'run',       null,null,null,null,'end' from dual union all
      6                   select 'id1',    3,   'elseif',    'ac',6,'>=',4,null from dual union all
      7                   select 'id1',    4,   'run',       null,null,null,null,null from dual union all
      8                   select 'id1',    5,   'else',      null,null,null,null,'end' from dual union all
      9                   select 'id1',    6,   'run',       null,null,null,null,null from dual union all
    10                   select 'id2',    1,   'run',       null,null,null,null,null from dual union all
    11                   select 'id2',    2,   'run',       null,null,null,null,null from dual union all
    12                   select 'id2',    3,   'if',        'an',5,'<=',5,null from dual union all
    13                   select 'id2',    4,   'run',       null,null,null,null,null from dual union all
    14                   select 'id2',    5,   'else',      null,null,null,null,'end' from dual union all
    15                   select 'id2',    6,   'run',       null,null,null,null,null from dual),
    16  tableB as (select 'id0' id, 'aa' checkname, 0 val from dual union all
    17             select 'id1', 'ac', 5 from dual union all
    18             select 'id1', 'ab', 8 from dual union all
    19             select 'id2', 'ab', 4 from dual union all
    20             select 'id2', 'an', 6 from dual)
    21             --
    22             select id, seq from (select tt.*, first_value(decode(flag,1,seq) ignore nulls) over (partition by id order by seq) FV from
    23             (select a.*, b.val, lag(nvl(nvl2(val,case check_ when '='  then decode(sign(val-checkvalue),0,1,0)
    24                                          when '>=' then decode(sign(val-checkvalue),-1,0,1)
    25                                          when '>'  then decode(sign(val-checkvalue),1,1,0)
    26                                          when '<=' then decode(sign(val-checkvalue),1,0,1)
    27                                          when '<'  then decode(sign(val-checkvalue),-1,1,0)
    28                                     end, decode(type,'else',1)),val)) over (partition by a.id order by seq)  flag, lag(type,1,type) over (partition by a.id order by seq) lag_type
    29                              from tableA a, tableB b
    30              where a.id=b.id(+)
    31                and a.checkname=b.checkname(+)
    32                order by 1,2) tt
    33  ) where (type='run' and lag_type='run') or seq=FV
    34  /
    ID         SEQ
    id0          1
    id0          2
    id0          3
    id1          2
    id2          1
    id2          2
    id2          6
    7 rows selected
    SQL> Message was edited by:
    Volder
    1> In my query I don't use FAIL column
    so I go consequently throug SEQ column order.
    Using MODEL - you could use FAIL values as dimension values for getting the next row needed.
    2> In my query If there're no needed values in TABLE B - the else part of your IF_CLAUSES will be triggered.
    3> Instead of huge case you can just create function that will get inputted 3 params: 2 values and check operator - and will return 1 if true, 0 if it is false.
    Just take these comments into account.

  • Need help over this Query

    Hi, I need the Result set in the given below form. 
    Can any one please help me with this. 
    I am not able to get the 2nd most recent login date in the separate column. 
    Concerned Columns: Login date, login date2, login difference 
    Login date = Most recent login by the user
    Login date 2= 2nd most recent login by the user
    Login difference =  difference between last 2 logins 
    Help!!
    DECLARE @ownerid INT=304,@offset INT=330,@totalsec INT=86400
    SELECT USERNAME, LOGIN_ID,EMAIL,DEPARTMENT,LOGIN_DATE, LOGOUT_DATE, IP_ADDRESS,MACHINE_NAME,TOTAL_LOGIN_TIME,LOGIN_NUMBER,
    ROW_NUMBER() OVER (ORDER BY USERNAME, LOGIN_ID) AS ROWNUMBER
    FROM
    SELECT Usr.UserID [USERID], usr.UserName [USERNAME],usr.LoginID [LOGIN_ID],
    usrcontact.Email [EMAIL],
    UsrContact.Department [DEPARTMENT],
    MAX(DateAdd(mi,@offset, UsrHis.LoginDate)) [LOGIN_DATE],
    MAX(DateAdd(mi,@offset, UsrHis.LogoutDate)) [LOGOUT_DATE],
    UsrHis.IPAddress [IP_ADDRESS],UsrHis.MachineName [MACHINE_NAME],
    convert( NVARCHAR(50),(DATEDIFF(SECOND,UsrHis.LoginDate,UsrHis.LogoutDate))/@totalsec) + ' '+'Days'+ ' '+
    convert( NVARCHAR(50),((DATEDIFF(SECOND,UsrHis.LoginDate,UsrHis.LogoutDate))%@totalsec)/3600) + ' '+'hours'+ ' '+
    convert( NVARCHAR(50),(((DATEDIFF(SECOND,UsrHis.LoginDate,UsrHis.LogoutDate))%@totalsec)%3600/60)) + ' '+'Minutes'+ ' '+
    convert( NVARCHAR(50),(((DATEDIFF(SECOND,UsrHis.LoginDate,UsrHis.LogoutDate))%@totalsec)%3600%60)) + ' '+'Seconds'
    [TOTAL_LOGIN_TIME],
    ROW_NUMBER() OVER (PARTITION BY USR.USERID ORDER BY USRHIS.LOGINDATE) LOGIN_NUMBER
    FROM Az_User Usr Inner Join LoginHistory UsrHis
    ON UsrHis.OwnerID=Usr.AppOwnerID
    and
    Usr.UserID = UsrHis.UserID
    inner join UserContact UsrContact
    ON UsrContact.CompanyID = Usr.AppOwnerID
    and UsrContact.UserID = Usr.UserID
    WHERE usr.AppOwnerID = @ownerid
    GROUP BY Usr.UserID,Usr.UserName , usrcontact.Email , UsrHis.LoginDate,usr.LoginID,UsrContact.Department,
    UsrHis.LogoutDate,UsrHis.IPAddress,UsrHis.MachineName,
    Dateadd(D, Datediff(D, 0, Dateadd(mi, @offset, UsrHis.LoginDate)), 0)
    ) AS TEMP
    WHERE TEMP.LOGIN_NUMBER <=2
    Hi here is the Data type of the columns i am selecting.. and the result i am getting. 
    But here the total_login_time is wrong. .
    I need difference between last 2 logins not length of the session.  

    It is unclear what you are trying to achieve... 
    DATEDIFF(d,Logindate,Logindate2)
    AS [Login difference]
    FROM.....
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • Need help with this query

    Hi,
    I am using SQL Server 2008 Enterprise edition 64 bit on Windows serer 2008 enterprise edition 64 bit.
    The below query works fine. I am trying to rewrite the code without using the sub query. In the end i should get the same results for both the query which we are going to rewrite and the below mentioned query.
    Can any help me please.
    SELECT
    t1.DOCUMENT_NO,
    RTRIM(CAST(t1."ENVIRONMENT_CD" AS VARCHAR(5))) + '*' + RTRIM(CAST(t1."ORDER_NO" AS VARCHAR(25)))
    +
    CASE WHEN (SELECT COUNT(DISTINCT S1.TEST_REPORTING_MATERIAL_SID)
    FROM dbo.TBLTEST S1 ON S1.DOCUMENT_NO = T1.DOCUMENT_NO
    WHERE S1.TEST_REPORTING_MATERIAL_SID > 0
    AND S1.COMPANY_CD = T1.COMPANY_CD AND S1.INVOICE_SEQ_NO = T1.INVOICE_SEQ_NO
    AND S1.DOCUMENT_ITEM_NO = T1.DOCUMENT_ITEM_NO
    AND S1.ORDER_NO = T1.ORDER_NO) > 1 THEN
    RTRIM(CAST(t1."TEST_REPORTING_MATERIAL_SID" AS VARCHAR(10)))
    ELSE
    END as sum_key,
    t1.SALES_ANALYSIS_CD
    FROM
    dbo.TBLTEST_ALL T1
    WHERE
    t1.TIME_SID >= 20001001 ;
    I tried to use a left outer Join , it did not work out. I tried to take the subquery and assign it to a variable and use in the above mentioned query. But i am not getting the same results.
    I don't want to use the above query so i am planning to rewrite the code.
    Thank You,

    I doubt that the query you posted works fine, because:
    FROM dbo.TBLTEST S1 ON S1.DOCUMENT_NO = T1.DOCUMENT_NO
    This is a syntax error. I will have to assume that your inteded query reads:
    SELECT t1.DOCUMENT_NO,
           rtrim(cast(t1."ENVIRONMENT_CD" AS varchar(5))) + '*' +
           rtrim(cast(t1."ORDER_NO" AS varchar(25))) +
          CASE WHEN (SELECT COUNT(DISTINCT S1.TEST_REPORTING_MATERIAL_SID)
                     FROM   dbo.TBLTEST S1
                     WHERE  S1.DOCUMENT_NO = T1.DOCUMENT_NO
                       AND  S1.TEST_REPORTING_MATERIAL_SID > 0
                       AND  S1.COMPANY_CD = T1.COMPANY_CD
                       AND  S1.INVOICE_SEQ_NO = T1.INVOICE_SEQ_NO
                       AND  S1.DOCUMENT_ITEM_NO = T1.DOCUMENT_ITEM_NO
                       AND  S1.ORDER_NO = T1.ORDER_NO) > 1 THEN
                     RTRIM(CAST(t1."TEST_REPORTING_MATERIAL_SID" AS VARCHAR(10)))
               ELSE  '*-'
          END as sum_key, t1.SALES_ANALYSIS_CD
    FROM   dbo.TBLTEST_ALL T1
    WHERE  t1.TIME_SID >= 20001001
    Here is a query with a left join. Whether it is actually better than the one you have I am not sure.
    SELECT t1.DOCUMENT_NO,
           rtrim(cast(t1."ENVIRONMENT_CD" AS varchar(5))) + '*' +
           rtrim(cast(t1."ORDER_NO" AS varchar(25))) +
          CASE WHEN S1."EXISTS" IS NOT NULL
               THEN  RTRIM(CAST(t1."TEST_REPORTING_MATERIAL_SID" AS varchar(10)))
               ELSE  '*-'
          END as sum_key, t1.SALES_ANALYSIS_CD
    FROM   dbo.TBLTEST_ALL T1
    LEFT   JOIN (SELECT 1 AS "EXISTS"
                 FROM   dbo.TBLTEST
                 WHERE  TEST_REPORTING_MATERIAL_SID > 0
                 GROUP  BY DOCUMENT_NO, COMPANY_CD, INVOICE_SEQ_NO,
                           DOCUMENT_ITEM_NO, ORDER_NO
                 HAVING COUNT(DISTINCT TEST_REPORTING_MATERIAL_SID) > 1) AS S1
             ON S1.DOCUMENT_NO = T1.DOCUMENT_NO
           AND  S1.COMPANY_CD = T1.COMPANY_CD
           AND  S1.INVOICE_SEQ_NO = T1.INVOICE_SEQ_NO
           AND  S1.DOCUMENT_ITEM_NO = T1.DOCUMENT_ITEM_NO
           AND  S1.ORDER_NO = T1.ORDER_NO
    WHERE  t1.TIME_SID >= 20001001
    Erland Sommarskog, SQL Server MVP, [email protected]

  • SQL I need help with this query Please help

    List the names of all the products whose weight unit measure is “Gram”.  Order the list by product name.  Do not use JOINS, but use the IN clause with a sub-query.
    select Name
    from UnitMeasure
    where Name= 'Gram'
    order by Name
    I did this, but it seem that the requirement is different.

    As a guess:
    Select Name from Product
    where UnitMeasure in (Select Name from unitmeasure where name = 'Gram')
    Andy Tauber
    Data Architect
    The Vancouver Clinic
    Website | LinkedIn
    This posting is provided "AS IS" with no warranties, and confers no rights. Please remember to click
    "Mark as Answer" and "Vote as Helpful" on posts that help you. This can be beneficial to other community members reading the thread.

  • Physician/Researcher needs help with this query

    Folks,
    Thank you in advance for looking at my problem. You are helping to save lives and make this world a better place.
    I am trying to find out the earliest date patients took steroid. I have:
    select patientid, visitnumber, steroid_start_date from treatments where steroid_start_date is not null and trim(steroid_start_date) != '/'
    order by patientid, substr(steroid_start_date, -4)
    I then have:
    patientid visitnumber steroid_start_date(this is a string column, not date or time, and it has so many junk in it, like /2003 , /)
    4 3 03/2004
    4 2 01/01/2005
    10 2 08/01/2005
    10 1 05/01/2002
    What I need is:
    4 3 03/2004
    10 1 05/01/2002
    I am not good with group by... having.... max.... How can I limit to one patient per row and this row is their earliest visit?
    Thank you very much in advance. You are helping to save lives.

    Here it is ->
    satyaki>
    satyaki>select * from v$version;
    BANNER
    Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Prod
    PL/SQL Release 10.2.0.3.0 - Production
    CORE    10.2.0.3.0      Production
    TNS for 32-bit Windows: Version 10.2.0.3.0 - Production
    NLSRTL Version 10.2.0.3.0 - Production
    Elapsed: 00:00:00.53
    satyaki>
    satyaki>
    satyaki>with t
      2  as
      3    (
      4       select 4 patientid, 3 visitnumber, '03/2004' steroid_start_date from dual
      5       union all
      6       select 4, 2, '01/01/2005' from dual
      7       union all
      8       select 10, 2, '08/01/2005' from dual
      9       union all
    10       select 10, 1, '05/01/2002' from dual
    11    )
    12  select patientid,
    13         visitnumber,
    14         steroid_start_date
    15  from (
    16         select k.*,
    17                row_number() over(partition by patientid order by to_date(substr(steroid_start_date,-4),'YYYY')) rn
    18         from t k
    19         order by patientid
    20       )
    21  where rn=1;
    PATIENTID VISITNUMBER STEROID_ST
             4           3 03/2004
            10           1 05/01/2002
    Elapsed: 00:00:00.11
    satyaki>Regards.
    Satyaki De.

  • I need information on this Object

    Hi, can one help me in this object.
                    On a monthly basis, after all data has been fed into One Source and the monthly One Source calculations have been performed, an extract will be run from One Source , converted via XI and loaded to BW.  The current plants that will be extracted from One Source are:  6101, 6102, 6103, 6201, 6202, 6203, 6301, 6302, 6601, and 6602.  As additional plants get converted to SAP; they will automatically start appearing on this extract.    The One Source extract file will be pulled from a corporate server for processing. (One source is the Data Warehouse)

    Hi Rahul,
    what expecting you exctly, hot to aciheve your requiremnt in XI.
    Suppose oneSource is File System.
    you want to send data to BI. Use File to ABAP Proxy .
    LET ME KNOW YOUR REQUIREMENT EXACTLY.
    Regards,
    Raj

  • I need Information on this intresting OBJECT

    On a monthly basis, after all data has been fed into One Source and the monthly One Source calculations have been performed, an extract will be run from One Source , converted via XI and loaded to BW.  The current plants that will be extracted from One Source are:  6101, 6102, 6103, 6201, 6202, 6203, 6301, 6302, 6601, and 6602.  As additional plants get converted to SAP; they will automatically start appearing on this extract.    The One Source extract file will be pulled from a corporate server for processing. (One source is the Data Warehouse)

    Please post this in BI section

Maybe you are looking for

  • Download Adobe Photoshop Elements 6.0

    HELP! I have a valid serial number for Photoshop Elements 6.0 from a purchased copy a couple of years back. I recently moved and reformatted my computer without realizing my install disks did not make it to the new house. I had backed up the entire A

  • Flash brush sensitivity help.

    In flash CC, my brush has no problem rendering, but when i put pressure sensitivity on, it all of a sudden will not show my strokes until i am done making the stroke

  • Parsing datestring to GregorianCalendar on Solaris.

    Hi There! I?m parsing strings to GregorianCalendar object with the class SimpleDateFormat. The problem is that when I?m running on a Windows platform everything works out great but when I deploy it on a Solaris platform the parser parse it wrongly. H

  • OMG! WHERE DID MY PHOTOS GO???

    What the **** happened??? I just bought a new 2013 iMac and was transferring music from my iTunes library (via a thumb drive) to the new one. When I went back to the older iMac (2009) and opened iPhoto, a window popped up saying "Which photo library

  • Importing java class in to xml

    is there any way to import a java class into an xml file.suppose if I have a class containing all static constants .Anfd if I want this constant vlaues in xml how to do that