Tuning query which is using joins.....

Hello ,
i have a following query and want to use bind variable .
so can you please assist me on that ???
SELECT aq.a, aq.b, COUNT(aa.c) AS qcount
FROM USER.TQ aq, USER.TGI agi,USER.TA aa
WHERE aa.d = aq.e
AND aq.f = 'Up'
AND agi.g = 'Tel'
AND aq.h = 'Tel'
AND aa.j = agi.k
AND aq.l = aa.m
AND TRUNC(agi.n(+)) BETWEEN TO_DATE('1/17/2006','MM/DD/YYYY') AND TO_DATE('4/3/2008','MM/DD/YYYY')
AND aa.x = 'No' AND y <> '0'
GROUP BY aq.a, aq.b
ORDER BY aq.a
thanks in advance...

so can you please assist me on that ???What's your problem: replacing literals with bind variables or passing values to bind variables at runtime? How are you going to run this query? SQL*Plus? PL/SQL? some other front end?
Cheers, APC
Blog : http://radiofreetooting.blogspot.com/

Similar Messages

  • Improving query which is using IN clause

    Hi,
    I am currently using a query which has IN (1.2.3....N) clause in where condition.
    The table has more than 100000 records in it. I have a set of 20 values which I pass inside this IN clause.
    The column which is used for IN clause is indexed.
    Can I use anything other than IN clause for this purpose?
    What is better way?
    Thanks,
    Plad

    > Can I use anything other than IN clause for this purpose? > What is better way?
    Sure you could use something else, but the IN clause would perfectly suit your needs. And the one who has to maintain the code after you are gone, will be glad you used IN, because it is as clear as you can get.
    If you are hinting at the fact that the query is too slow, then please read [url http://forums.oracle.com/forums/thread.jspa?threadID=501834&tstart=0]this thread and try to find out how many rows out of the 100K satisfy your IN predicate.
    Regards,
    Rob.

  • Unable to execute update query. Can't we use a query within a update query which also has joins?

    Below is the query:
    UPDATE 
    (select * from [HR_DEV_DM].[CFQ_TEST].CFQ_Referrals as CFRQ
    LEFT JOIN [HR_DEV_DM].[CFQ_TEST].t_Chg_Rsns as CHGRSNS
    ON CFRQ.RecChangeID = CHGRSNS.Chg_ReasID)
    INNER JOIN [HR_DEV_DM].[CFQ_TEST].t_Qt_Typs
    ON [HR_DEV_DM].[CFQ_TEST].CFQ_Referrals.QuoteType = [HR_DEV_DM].[CFQ_TEST].t_Qt_Typs.Qt_Typ 
    SET [HR_DEV_DM].[CFQ_TEST].CFQ_Referrals.RecKey = dbo.BuildRecordKey([HR_DEV_DM].[CFQ_TEST].CFQ_Referrals.[ReferralCode], [HR_DEV_DM].[CFQ_TEST].CFQ_Referrals.[RetentionID],
    [HR_DEV_DM].[CFQ_TEST].CFQ_Referrals.[ClientFName],[HR_DEV_DM].[CFQ_TEST].CFQ_Referrals.[ClientLName], 
    IIf([HR_DEV_DM].[CFQ_TEST].t_Qt_Typs.Qt_Grp='MOAT',[HR_DEV_DM].[CFQ_TEST].CFQ_Referrals.[QuotePolicyType],[HR_DEV_DM].[CFQ_TEST].CFQ_Referrals.[ClientZip]),
    [HR_DEV_DM].[CFQ_TEST].[CFQ_Referrals].[QuoteType])
    WHERE ((([HR_DEV_DM].[CFQ_TEST].CFQ_Referrals.RecProcessed)=0) 
    AND (([HR_DEV_DM].[CFQ_TEST].CFQ_Referrals.RecChange)=Yes) 
    AND (([HR_DEV_DM].[CFQ_TEST].t_Chg_Rsns.ImpactsRecKey)=Yes)) 
    OR ((([HR_DEV_DM].[CFQ_TEST].CFQ_Referrals.RecKey) Is Null)) OR ((([HR_DEV_DM].[CFQ_TEST].CFQ_Referrals.RecKey)=''));
    When I run this query, below are the errors I see:
    Msg 102, Level 15, State 1, Line 2
    Incorrect syntax near '('.
    Msg 156, Level 15, State 1, Line 6
    Incorrect syntax near the keyword 'INNER'.
    Msg 102, Level 15, State 1, Line 14
    Incorrect syntax near 'HR_DEV_DM'.
    Msg 102, Level 15, State 1, Line 17
    Incorrect syntax near 'HR_DEV_DM'.
    Msg 102, Level 15, State 1, Line 17
    Incorrect syntax near 'HR_DEV_DM'.
    I don't see any problem with 'HR_DEV_DM'. Because,  I was able to run the below queries:
    select * from [HR_DEV_DM].[CFQ_TEST].t_Chg_Rsns
    select * from [HR_DEV_DM].[CFQ_TEST].t_Qt_Typs where Qt_Typ = 'Auto/Cycle'
    select * from [HR_DEV_DM].[CFQ_TEST].CFQ_Referrals where QuoteType = 'MOAT'
    Please help.......

    What you are trying to achieve is possible, it's just a matter of syntax.
    UPDATE [HR_DEV_DM].[CFQ_TEST].CFQ_Referrals
    SET [HR_DEV_DM].[CFQ_TEST].CFQ_Referrals.RecKey = dbo.BuildRecordKey([HR_DEV_DM].[CFQ_TEST].CFQ_Referrals.[ReferralCode], [HR_DEV_DM].[CFQ_TEST].CFQ_Referrals.[RetentionID],
    [HR_DEV_DM].[CFQ_TEST].CFQ_Referrals.[ClientFName],[HR_DEV_DM].[CFQ_TEST].CFQ_Referrals.[ClientLName],
    IIf([HR_DEV_DM].[CFQ_TEST].t_Qt_Typs.Qt_Grp='MOAT',[HR_DEV_DM].[CFQ_TEST].CFQ_Referrals.[QuotePolicyType],[HR_DEV_DM].[CFQ_TEST].CFQ_Referrals.[ClientZip]),
    [HR_DEV_DM].[CFQ_TEST].[CFQ_Referrals].[QuoteType])
    FROM
    select * from [HR_DEV_DM].[CFQ_TEST].CFQ_Referrals as CFRQ
    LEFT JOIN [HR_DEV_DM].[CFQ_TEST].t_Chg_Rsns as CHGRSNS
    ON CFRQ.RecChangeID = CHGRSNS.Chg_ReasID
    INNER JOIN [HR_DEV_DM].[CFQ_TEST].t_Qt_Typs
    ON [HR_DEV_DM].[CFQ_TEST].CFQ_Referrals.QuoteType = [HR_DEV_DM].[CFQ_TEST].t_Qt_Typs.Qt_Typ
    WHERE ((([HR_DEV_DM].[CFQ_TEST].CFQ_Referrals.RecProcessed)=0)
    AND (([HR_DEV_DM].[CFQ_TEST].CFQ_Referrals.RecChange)=Yes)
    AND (([HR_DEV_DM].[CFQ_TEST].t_Chg_Rsns.ImpactsRecKey)=Yes))
    OR ((([HR_DEV_DM].[CFQ_TEST].CFQ_Referrals.RecKey) Is Null)) OR ((([HR_DEV_DM].[CFQ_TEST].CFQ_Referrals.RecKey)=''))) A
    WHERE [HR_DEV_DM].[CFQ_TEST].CFQ_Referrals.RecChangeID = A.RecChangeID

  • How to pass Multi and Singlr value Parameters to DB2 query, which is using in SSRS report for ODBC connection

    Hi Guys,
    I am using DB2 database in SSRS. I have to pass Single Value and Multi Value Parameters. I tried with Select * From DB2Table Where
    Column=@PRM_Name Or Select * From DB2Table Where
    Column=:PRM_Name . It is not working and throwing error. Please help me out.
    Connection Details: ODBC
    Thanks Shiven:)

    Hi SKM,
    So you mean to say that Go to DataSource->Add Dataset-> Query Type-Text-> Under Query:
    click on fx (Expression)-> Write this expression
    For Single Value Parameter:
    ="SELECT customer_name, telephone_number, address1, address2, city from MyTable
    WHERE city = '" + Parameters!City.Value + "'"
    OR
    ="SELECT customer_name, telephone_number, address1, address2, city from MyTable
    WHERE city =  '" & Parameters!City.Value & "'"
    Keep it in mind if Parameter is String then
    It should be in Single quote ''.
     Like
    ="SELECT customer_name, telephone_number, address1, address2, city from MyTable WHERE city
    ='Hyderabad' "
    For Multivalu Parameter:
    ="SELECT EmployeeID, FirstName, LastName, LoginID FROM SHIVEN.AUDIT Where FirstName
    in ('" + REPLACE(JOIN(Parameters!City.Value,","),",","','") + "')"
    NOTE:
    If your Parameter is Single Value Parameter and You want to enter string values with Coma (,)
    separated (Like Hyderabad, Chennai, Delhi).
    In this case, you have to use below expression.
    ="SELECT customer_name, telephone_number, address1, address2, city from MyTable
    WHERE city IN ('" + REPLACE(Parameters!City.Value ,",","','") + "')"
    OR
    ="SELECT customer_name, telephone_number, address1, address2, city from MyTable
    WHERE city IN  ('" & REPLACE(Parameters!City.Value ,",","','") & "')"
    In above expression: Replace will replace all , with ‘,’ and city IN (‘Hyderabad’, ‘Chennai’,
    ‘Delhi’) will not throw any error.
     Note: You have to write expression in one line in Expression editor for dataset
    query
    Thanks It is working fine but it is tough job if query is big.
    Hi S kumar,
    The above approach we use when we have source like DB2, becasue DB2 has some syntactical differences to pass multivalue paramaeter. I tested and it works good, if i am mentioning the query in above format by using Fx button while creating dataset.
    but if we want fetch data from view which exist in DB2 and we need to call db2 view in SSRS and pass multivalue parameter in a way we did above then could you please mention the steps and way to achieve this.
    Thanks in advance!

  • Get query using joins

    My Table
    employee table
    =emp id .. emp name
    1    Ravi
    2    Kumar
    3    Gopal
    4    Selvam
    5    Raj
    6    Sekar
    dept table
    dept id .. emp id .. salary
    1                  1    10000
    1                  2    20000
    2                   3    30000
    2                     4    40000
    Query
    1. Using Join, select Employees not in the dept table
    2. select max  of salary , dept id , emp_Name from dept  group by dept
    Kindly provide me the query.
    ShanmugaRaj

    Looks like homework/exercise given to you. Did you try to write queries by yourself? :)
    You may ask your doubts/confusion.
    -- 1)
    SELECT e.empid
    ,e.empname
    FROM employee e
    LEFT JOIN dept d ON e.empid = d.empid
    WHERE d.empid IS NULL
    --2)
    SELECT MAX(d.salary)
    ,d.deptid
    ,e.empName
    FROM dept d
    FULL JOIN employee e ON d.empid = e.empid
    GROUP BY d.deptid, e.empname
    -Vaibhav Chaudhari

  • How can i fetch records from 3 tables in a single query  without using join

    Hi.
    Can any body please tell me <b>How can i fetch records from 3 tables with a single query  without using joins</b>
    Thanx
    prabhudutta

    Hi Prabgudutta,
    We can fetch the data by using the views concept.
    Go throuth this info we can know the how to create view and same like database table only we can fetch the data.
    Views conatin the data at runtime only.
    Four different view types are supported. These differ in the
    way in which the view is implemented and in the methods
    permitted for accessing the view data.
    Database views are implemented with an equivalent view on
    the database.
    Projection views are used to hide fields of a table (only
    projection).
    Help views can be used as selection method in search helps.
    Maintenance views permit you to maintain the data
    distributed
    on several tables for one application object at one time.
    step by step creation of Maintenance view:
    With the help of the table maintenance generator, you are able to maintain the ENTRIES of the table in SM30 transaction.
    It can be set in transaction SE11 - Tools - Table maintenance generator.
    Table maintanance Generator is used to manually input values using transaction sm30
    follow below steps
    1) go to se11 check table maintanance check box under attributes tab
    2) utilities-table maintanance Generator-> create function group and assign it under
    function group input box. Also assign authorization group default &NC& .
    3) select standard recording routine radio in table table mainitainence generator to move table
    contents to quality and production by assigning it to request.
    4) select maintaience type as single step.
    5) maintainence screen as system generated numbers this dialog box appears when you click on create button
    6) save and activate table
    One step, two step in Table Maintenance Generator
    Single step: Only overview screen is created i.e. the Table Maintenance Program will have only one screen where you can add, delete or edit records.
    Two step: Two screens namely the overview screen and Single screen are created. The user can see the key fields in the first screen and can further go on to edit further details.
    SM30 is used for table maintenance(addition or deletion of records),
    For all the tables in SE11 for which Table maintenance is selected , they can be maintained in SM30
    Sm30 is used to maintain the table ,i.e to delete ,insert or modify the field values and all..
    It creates the maintenance screen for u for the aprticular table as the maintenance is not allowed for the table..
    In the SE11 delivery and maintenance tab, keep the maintenance allowed..
    Then come to the SM30 and then enter the table name and press maintain..,
    Give the authorization group if necessary and give the function group and then select maintenance type as one step and give the screen numbers as system specified..
    Then create,,,
    Then u will able to see the maintenance view for the table in which u can able to insert and delete the table values...
    We use SM30 transaction for entering values into any DB table.
    First we create a table in SE11 and create the table maintenance generator for that Table using (utilities-> table maintenance generator) and create it.
    Then it will create a View.
    After that from SM30, enter the table name and Maintain, create new entries, change the existing entries for that table.
    Hope this resolves your query.
    Reward all the helpful answers.
    Rgds,
    P.Naganjana Reddy

  • About SQL Query using joins

    Hi,
    I want to write a SQL statement using Joins. The base table "A" has about 100 fields and the join table "B" a few. I would like to fetch all fields from table "A" and a few from table "B".
    Is there a way to write a query wherein I can use "Select * " for table "A" rather than writing all 100 field name in the query? Please keep in mind that I want to use a Join.
    Thanks.

    Hi Thomas,
    but if there are some fields which are in both tables, SELECT * will be not sufficient. E.g. fields ERNAM, ERDAT, AENAM, AEDAT are such fields which can occur in more tables. In case that a target area will contain these fields, by * with addition INTO CORRESPONDING FIELDS OF, you are not able to specify from which table these values should be taken. In such case, it can be solved by specifying field list dynamically. If it is not that case SELECT * is sufficient. You should check intersection of common fields for tables you are joining. Thereafter you should decide if you can use SELECT *.
    Maybe for better understanding, what exactly I am talking about, look at this example:
    TYPES: BEGIN OF ts_data,
            ernam TYPE mara-ernam,
           END OF ts_data.
    DATA: ls_data TYPE ts_data,
          ls_mara TYPE mara,
          ls_mchb TYPE mchb.
    START-OF-SELECTION.
      ls_mara-matnr = '1'.
      ls_mchb-matnr = ls_mara-matnr.
      ls_mara-ernam = 'A'.
      ls_mchb-ernam = 'B'.
      INSERT mara FROM ls_mara.
      INSERT mchb FROM ls_mchb.
      SELECT SINGLE * FROM mara INNER JOIN mchb ON mara~matnr = mchb~matnr INTO CORRESPONDING FIELDS OF ls_data.
      ROLLBACK WORK.
    You as a developer are not able to tell from which table common fields should be selected. But maybe this is really too specific case...
    Regards,
    Adrian

  • Using join and batch reading in the same query

    Hi,
    I wonder if it is possible to use "Joining" and "batch reading" in the same query.
    For example I Have
    A -> 1-1 B
    A -> 1-1 B
    B -> 1-M C
    This is the case where I have two separate 1-1 relationships to the same class B from A. Toplink 10.0.3 can manage it nicely through joining.
    Now, I would like to read a set of As (with its 2 Bs) and all Cs for each B.
    It seems that the following configuration does not work:
    A -> 1-1 B (use joining)
    A -> 1-1 B (use joining)
    B -> 1-M C (Batch read)
    Any help would be greatly appreciated
    Tony.

    James,
    Would you be so kind to look at the following code?
    Am I formulating it correctly to achieve my desired behavior?
    Trip.class -> 1-1 PickupStop
    Trip.class -> 1-1 DropoffStop
    PickupStop and DropoffStop extend Stop and use same table (STOP)
    Stop -> 1-M StopEvents
    I would like to fetch all Trips, with their Stops and all StopEvents in 2 queries:
    1. Trip joined with Stop
    2. Batchread StopEvents
    Code:
    ReadAllQuery raq = new ReadAllQuery(Trip.class);
    Expression qexp1 = new ExpressionBuilder();
    Expression qexp2 = new ExpressionBuilder();
    raq.addJoinedAttribute("pickupStop");
    raq.addJoinedAttribute("dropoffStop");
    raq.addBatchReadAttribute(qexp1.get("pickupStop").get("vStopEvents"));
    raq.addBatchReadAttribute(qexp2.get("dropoffStop").get("vStopEvents"));

  • Bex Query which uses Dynamic columns to display actuals

    Hi Bex experts,
    I have a query issue/question.
    I currently have a Bex query which shows me the the planned values for each period, spanning 6 years into the future. My Key figure columns are defined as follows:
    Value type  = '020'
    Version  = mandatory variable, entered at execution.
    Posting period (FISCPER3)  = These columns are fixed values using periods 1 to 12 for each column.
    Fiscal year (0FISCYEAR) = Each column contains SAP exit for current year, and using the offset +1, +2, +3, +4 etc, when I define the future years coulmns.
    Currency = fixed 'USD'.
    Fiscal year variant = fixed 'Z4'
    The above works fine for plan data.
    I want to now include is:
    Seperate 'Dynamic columns' to show only actuals for period ranges from period one to the previous period (or current period minus 1). Each period should have it's own column for actuals.
    The dynamic actuals columns should be grouped together to the left of the plan columns.
    Actuals are only for current year, so I will still use the SAP EXIT for current year in the column definition.
    Example: If I am currently in period 10, the query should show me actuals from period 1 to period 9 in seperate columns, then continue to show me my plan values columns that I have in place already.
    How can I construct these actuals columns in to my existing query. If you have possible screens shots.
    Thanks, and maximum points will be alotted.

    The way I have approached this you may not like as it involves quite a bit of coding
    12 CKFs
    each CKF adds up 2 RKFs
    So 24 RKFs
    example Column 6 CKF
    Adds Column 6 RKF Actual and Column 6 RKF Plan
    Column 6 RKF Actual contains Actual version + key figure + Period variable column 6 Actual
    Column 6 RKF Plan contains Plan version + key figure + Period Variable column 6 Plan
    Period variable column 6 Actual
    is a cmod variable which reads the entered date
    if the period of entered date is LE 6
    then return period 6 into "Period variable column 6 Actual"
    else put 0 into "Period variable column 6 Actual"
    Period variable column 6 Plan
    is a cmod variable which reads the entered date
    if the period of entered date is LE 6
    then return period 0 into "Period variable column 6 Plan"
    else put 6 into "Period variable column 6 Plan"
    Now what happens is that if you enter period 6 in your selection screen all the Actuals of columns greater than 6 all have period 0 put into their selection so return 0 and all the columns less than or equal to 6 return the values for the fiscal period (ie column 1 gets period 1)
    And in addition all the Plans columns return the value of their column ie for their period for those greater than 6 and for those less than 6 they all return 0
    It's convulted - but you get the idea - and yes it works
    There may be a better way to do it - and I am open to suggestions
    (this does assume that NOTHING is posted to period 0 otherwise it won't work)

  • Issues with query using joins in 3 tables

    I am trying to fetch data from 3 tables (Project,RIsk and Issues) using join. There are Risks associated with some projects and Issues associated with some projects.
    ProjectID is primary key in Project table.
    RiskID is primary key in risk table. ProjectID is foreign key.
    IssueID is primary key in Issue table.ProjectID is foreign Key.
    I need the projectname, count of risks for projects, count of issues for projects. I am using joins in all the 3 tables. Issue here is, its giving me double of count of risks and issues for each project.
    Please advise how can I get the correct number. I have used the below query,
    select p.projectname,count(r.riskid),count(i.issueid) from project as p
    left outer join risk as r on p.projectid=r.projecctid
    left outer join issue as i on p.projectid=i.projectid
    group by
    p.projectname
    thanks

    Hi All,
    I got a new requirement to count, the number of high priority risks as well as high priority issues along with the other details. I modified the below table to include the changes, but I am not getting the desired result. Could you please help?
    Original query:
    select p.projectname,count(distinct r.riskid), count(distinct i.issueid) from project as p
    left outer join risk as r on p.projectid=r.projecctid
    left outer join issue as i on p.projectid=i.projectid
    group by p.projectname
    Modified query:
    select p.projectname,count(distinct r.riskid),sum(case when r.riskpriority='high' then 1 else 0 end), sum(case when i.issuepriority='high' then 1 else 0 end),count(distinct i.issueid) from project as p
    left outer join risk as r on p.projectid=r.projecctid
    left outer join issue as i on p.projectid=i.projectid
    group by p.projectnameI should get the desired result as:XYZ,8,1,4,4But I am getting:XYZ,8,4,4,32thanks for the reply.

  • Opitmizing sql query using join

    Hello all,
    I have the following query that needs to be written using Joins. I am not sure if this is the correct place to post this question
    Tables used:
    1. activities: (a_id, n_id, market, amount, act_type, act_number, act_seq) --the money paid by the registrant for the market.
    2. market_reg (a_id, n_id, market, reg_stage) -- for each market there are registrants
    3. market (market) -- stores market details
    I need to get sum of total_payment_amount using the condition. I know the query is not opitmized and its not the correct way to get info. I was
    wondering if you guys can suggest me a query that will pull the information by using joins
    SELECT a.a_id, a.n_id, SUM (a.total_payment_amount)
    FROM activities a
    WHERE a.market = 'marketname'
    AND a.a_id||a.n_id IN
    (SELECT mr.a_id||mr.n_id
    FROM market_reg mr
    WHERE mr.market = 'marketname'
    AND mr.reg_stage = 'P'
    AND mr.n_id <> 0)
    AND (a.act_type = 'A'
    OR (a.act_type IS NULL
    AND a.act_number||act_seq IN
    ( SELECT a1.act_number||a1.act_seq
    FROM activities a1
    WHERE a1.market = 'marketname'
    GROUP BY a1.act_number||a1.act_seq
    HAVING COUNT (a1.act_number||a1.act_seq) = 1)))
    GROUP BY a.a_id, a.n_id;
    Thanks

    Hi,
    I see you have already re-posted this on a more appropriate forum, the SQL and PL/SQL forum.
    Thanks,
    Gary

  • Query using JOIN

    Hi,
    my tables structure looks:
    Column names:
    rhead
    bu
    sub_bu
    report_order
    sub_bu_order
    q1py
    My query is:
    select Rhead,bu,Sub_bu,report_order,sub_bu_order,q1py,case
              when sub_bu='ISS' then (select q1py from tsg a where a.sub_bu='ESS' and a.rhead=b.rhead)
              when sub_bu='TS' then (select q1py from tsg a where a.sub_bu='Services' and a.rhead=b.rhead)
              when sub_bu='SW' then (select q1py from tsg a where a.sub_bu='SW' and a.rhead=b.rhead)
              else NULL end as q1py_bu,
              case
              when sub_bu='ISS' then (select q1py from tsg a where a.sub_bu='TSG' and a.rhead=b.rhead)
              when sub_bu like 'R&D' and rhead in ('Region owned opex','% of revenue','Region opex','Region opex%') then
              (select q1py from tsg a where a.sub_bu like 'TSG' and a.rhead=b.rhead)
              else NULL end as q1py_tot from tsg b where report_order=1
    Result:
    rhead bu sub_bu report_order sub_bu_order q1py q1py_bu q1py_tot
    orders ESS ISS 1 1 1162 1778.4 2953.9
    here i am using the sub query to produce the result. I need to give the same result by using JOINS.
    So any one help me, by using JOINS instead of SUB QUERY and produce the same result
    Thanx in advance

    Hi,
    this is my query
    select
    Rhead,BU,Sub_bu,report_order,sub_bu_order,q1py,
    case
              when sub_bu='ISS' then (select q1py from tsg a where a.sub_bu='ESS' and a.rhead=b.rhead)
              when sub_bu='TS' then (select q1py from tsg a where a.sub_bu='Services' and a.rhead=b.rhead)
              when sub_bu='SW' then (select q1py from tsg a where a.sub_bu='SW' and a.rhead=b.rhead)
              else NULL end as q1py_bu,
    case
              when sub_bu='ISS' then (select q1py from tsg a where a.sub_bu='TSG' and a.rhead=b.rhead)
              when sub_bu like 'R&D' and rhead in ('Region owned opex','% of revenue','Region opex','Region opex%') then
              (select q1py from tsg a where a.sub_bu like 'TSG' and a.rhead=b.rhead)
              else NULL end as q1py_tot
    last_update from tsg where @condition;
    i will use the different conditions. they are
    1.sub_bu<>bu and report_order<=8
    2.report_order > 8 and report_order<11 and sub_bu not in (‘TSG’)
    3.report_order > 10 and report_order <14
    4.report_order > 13
    i used the above query and getting some time.
    so i am using the below query as suggested by forum earlier.
    select
    Rhead,BU,Sub_bu,report_order,sub_bu_order,q1py,
    case
    when sub_bu='ISS'
    then max(case when sub_bu='ESS' then q1py end) over(partition by rhead)
    when sub_bu='TS'
    then max(case when sub_bu='Services' then q1py end) over(partition by rhead)
    when sub_bu='SW'
    then max(case when sub_bu='SW' then q1py end) over(partition by rhead)
    end as q1py_bu,
    case
    when sub_bu='ISS'
    then max (case when sub_bu='TSG' then q1py end) over (partition by rhead)
    when sub_bu = 'R&D' and rhead in ('Region owned opex','% of revenue','Region opex','Region opex%')
    then max(case when sub_bu = 'TSG' then q1py end) over (partition by rhead)
    end as q1py_tot, last_update from tsg where @condition;
    I am getting better result by this query.
    but the problem is this query gives wrong output for first two conditions(1.sub_bu<>bu and report_order<=8
    2.report_order > 8 and report_order<11 and sub_bu not in (‘TSG’). The value is not displayed for the virtual column q1py_bu and q1py_tot.
    i am getting this warning message too
    Warning: Null value is eliminated by an aggregate or other SET operation.
    I am not able to find the solution. so plz do help in this..
    other than this every thing is fine
    thanks

  • 2 Questions How to use join() and Which is best coding pratice.

    Hi All,
    I have 2 Question:
    I have a MultipleThread class and when I try to use join method of thread class I get compile time error(so i commented it out).I also wanted to know is the best approch to write a threaded program.I also wanted to know about the best coding pratice for threadand also do I need to declare Instance variable thread and name(Is it possible to create multiple thread with out declaring instance variable thread and name , if yes which one is the better way 1> with instance variable 2> with out instance variable)

    Sorry here is the code.
    package javaProg.completeReferance;
    public class MultipleThread implements Runnable
         Thread thread;
         String name;
         MultipleThread(String nam)
              this.name=nam;
              thread = new Thread(this,name);
              thread.start();
         public void run()
              try
                   for (int i=1;i<=10;i++ )
                        Thread.sleep(1000);
                        System.out.println("Thread "+name+" "+i);
              catch (InterruptedException e)
                   System.out.println(""+e);
         public static void main(String [] args)
              try
                   MultipleThread t1=new MultipleThread("One");
                   MultipleThread t2=new MultipleThread("Two");
                   MultipleThread t3 =new MultipleThread("Three");
                   //t1.join();
                   //t2.join();
                   //t3.join();
                   for (int i=1;i<=10;i++ )
                        Thread.sleep(1000);
                        System.out.println("Parent Thread "+i);
              catch (InterruptedException e)
                   System.out.println(" "+e);
    }

  • Converting query to use joins

    My current query works perfectly.
    SELECT so.* FROM shipping_order so WHERE (so.submitter = 20) OR (so.requestor_id IN (SELECT poc.objid FROM point_of_contact poc WHERE poc.ain = 20)) OR so.objid IN (SELECT ats.shipping_order_id FROM ac_to_so ats WHERE (ats.access_control_id IN (selectac. objid FROM access_control ac WHERE ac.ain = 20 OR ac.group IN ('buyers', 'managers'))))
    But when I try to create it using join statements I do not get the correct results, or any results for that matter.
    Here is the query with joins.
    SELECT so.* FROM shipping_order so INNER JOIN point_of_contact ON (so.requestor_id = poc.objid AND poc.ain = 20) INNER JOIN ac_to_so ats ON (so.objid = ats.shipping_order_id) INNER JOIN access_control ac ON (ats.access_control_id = ac.objid AND (ac.group IN ('buyers', 'managers') OR ac.ain = 20)) WHERE (so.submitter = 20)
    Any ideas on what I am doing wrong. I tried outer joins as well and did not get the results either.
    TIA.
    Edited by: user9522282 on Mar 11, 2009 6:27 AM fixed typo

    Oh sorry. Here is the sql. Thanks!
    create table point_of_contact
         objid number not null,
         ain number not null,
         constraint point_of_contact_pk primary key (objid)
    create table access_control
         objid number not null,
         ain number,
         user_group varchar2(64 byte),
         constraint access_control_pk primary key (objid)
    create table shipping_order
         objid number not null,
         submitter number not null,
         requestor_id number not null,
         constraint shipping_order_pk primary key (objid)
    create table ac_to_so
         shipping_order_id number not null,
         access_control_id number not null,
         constraint ac_to_so_pk primary key (shipping_order_id, access_control_id),
         constraint ac_to_so_access_control_fk1 foreign key (access_control_id)
              references access_control (objid),
         constraint ac_to_so_shipping_order_fk1 foreign key (shipping_order_id)
              references shipping_order (objid),
    insert into point_of_contact (objid,ain) values (2,37);
    insert into point_of_contact (objid,ain) values (1,20);
    insert into access_control (objid, ain) values (1, 20);
    insert into access_control (objid, user_group) values (2, 'managers');
    insert into shipping_order (objid, submitter, requestor_id) values (1,20,1);
    insert into shipping_order (objid, submitter, requestor_id) values (2,23,2);
    insert into shipping_order (objid, submitter, requestor_id) values (3,23,2);
    insert into ac_to_so (shipping_order_id, access_control_id) values (1, 1);
    insert into ac_to_so (shipping_order_id, access_control_id) values (2, 2);
    select so.* from shipping_order so where (so.submitter = 20)
         or (so.requestor_id in (select poc.objid from point_of_contact poc where poc.ain = 20))
         or so.objid in (select ats.shipping_order_id from ac_to_so ats where
         (ats.access_control_id in (select ac.objid from access_control ac where ac.ain = 20
         or ac.user_group in ('buyers', 'managers'))));

  • Write the following query using JOIN keyword ?

    Qest:
    Write the following query using JOIN keyword ?
    select ID_category from category_master X
    where Exist(select 1 from sub_category Y where
    X.ID_category=Y.ID_category)Edited by: 799660 on Oct 3, 2010 6:05 AM

    select  X.ID_category
      from  category_master X join (select distinct ID_category from sub_category) Y
             on (X.ID_category=Y.ID_category)
    /SY.

Maybe you are looking for

  • Even after being "fixed", my connection is still u...

    Been with BT since late December, using infinity 2 with HH5. Live in a block of flats. When we first got the package we were being disconnected every few hours, often several times per hour. Finally got some help from a mod on here who ran some tests

  • Please HELP!  my computer is FUBAR, seriously...

    i just did a clean install of Tiger on a partition of maindrive in 2002 Quicksilver 867mHz, 1.25G RAM, installation went fine but it was very buggy. I did all the updates, incl combined 10.4.11. The most disconcerting bug was that i couldn't restart

  • CSS burn error - device not supported

    I am getting a "This device does not support copy generation management..." error while burning a disc that is checked for CSS. Have tried this on my macpro tower, macbook pro, and even my old G4. By "device" do they mean the physical DVD drive/burne

  • Error on Calling Methods Using an Object of a Class

    I keep getting the error cannot resolve variable addStud . I can't figure out why. I've created objects of classes before this way, then called methods within that class like this and it worked fine. I can't discern any difference between the syntax

  • Why is share screen saying that it is being closed out by a remote user

    I'm using my mac mini and I am trying to share screen another computer by using iMessages on my mac to do that. Every time the other user clicks accept. It give me a window saying that "Your Screen Sharing session has been closed by a remote user".