Need help with Query

Hi,
Good day everyone! I need help writing a query. I have this table with the following data in them...
ACCT_CODE  FSYR      YTD_AMT
A123            11          100  
A456            11          200
A123            10          50
A456            10          100I want the output to look like this:
ACCT_CODE     CURRENT_YEAR(11)       PRIOR_YEAR(10)
A123               100                              50
A456               200                              100The user will input the fiscal year and based on that input, I want to get the prior year value as well.
Thank you for all your help!!
Edited by: user5737516 on Jun 29, 2011 6:48 AM
Edited by: user5737516 on Jun 29, 2011 6:50 AM

user5737516 wrote:
Hi,
Good day everyone! I need help writing a query. I have this table with the following data in them...
ACCT_CODE FSYR YTD_AMT
A123 11 100
A456 11 200
A123 10 50
A456 10 100
I want the output to look like this:
ACCT_CODE CURRENT_YEAR PRIOR_YEAR
A123 100 50
A456 200 100
The user will input the fiscal year and based on that input, I want to get the prior year value as well.
Thank you for all your help!!what is prior year?

Similar Messages

  • Need help with query joining several tables into a single return line

    what i have:
    tableA:
    puid, task
    id0, task0
    id1, task1
    id2, task2
    tableB:
    puid, seq, state
    id0, 0, foo
    id0, 1, bar
    id0, 2, me
    id1, 0, foo
    id2, 0, foo
    id2, 1, bar
    tableC:
    puid, seq, date
    id0, 0, 12/21
    id0, 1, 12/22
    id0, 2, 12/22
    id1, 0, 12/23
    id2, 0, 12/22
    id2, 1, 12/23
    what i'd like to return:
    id0, task0, 12/21, 12/22, 12/22
    id1, task1, 12/23, N/A, N/A
    id2, task2, 12/22, 12/23, N/A
    N/A doesn't mean return the string "N/A"... it just means there was no value, so we don't need anything in this column (null?)
    i can get output like below through several joins, however i was hoping to condense each "id" into a single line...
    id0, task0, 12/21
    id0, task0, 12/22
    id0, task0, 12/23
    id1, task1, 12/23
    is this possible fairly easily?
    Edited by: user9979830 on Mar 29, 2011 10:53 AM
    Edited by: user9979830 on Mar 29, 2011 10:58 AM

    Hi,
    Welcome to the forum!
    user9979830 wrote:
    what i have:...Thanks for posting that so clearly!
    Whenever you have a question, it's even better if you post CREATE TABLE and INSERT statements for your sample data, like this:
    CREATE TABLE     tablea
    (       puid     VARCHAR2 (5)
    ,     task     VARCHAR2 (5)
    INSERT INTO tablea (puid, task) VALUES ('id0',  'task0');
    INSERT INTO tablea (puid, task) VALUES ('id1',  'task1');
    INSERT INTO tablea (puid, task) VALUES ('id2',  'task2');
    CREATE TABLE     tablec
    (       puid     VARCHAR2 (5)
    ,     seq     NUMBER (3)
    ,     dt     DATE          -- DATE is not a good column name
    INSERT INTO tablec (puid, seq, dt) VALUES ('id0',  0,  DATE '2010-12-21');
    INSERT INTO tablec (puid, seq, dt) VALUES ('id0',  1,  DATE '2010-12-22');
    INSERT INTO tablec (puid, seq, dt) VALUES ('id0',  2,  DATE '2010-12-22');
    INSERT INTO tablec (puid, seq, dt) VALUES ('id1',  0,  DATE '2010-12-23');
    INSERT INTO tablec (puid, seq, dt) VALUES ('id2',  0,  DATE '2010-12-22');
    INSERT INTO tablec (puid, seq, dt) VALUES ('id2',  1,  DATE '2010-12-23');This way, people can re-create the problem and test their ideas.
    It doesn't look like tableb plays any role in this problem, so I didn't post it.
    Explain how you get the results from that data. For example, why do you want this row in the results:
    PUID  TASK  DT1        DT2        DT3
    id0   task0 12/21/2010 12/22/2010 12/22/2010rather than, say
    PUID  TASK  DT1        DT2        DT3
    id0   task0 12/22/2010 12/21/2010 12/22/2010? Does 12/21 have to go in the first column because it is the earliest date, or is it because 12/21 is related to the lowest seq value? Or do you even care about the order, just as long as all 3 dates are shown?
    Always say what version of Oracle you're uisng. The query below will work in Oracle 9 (and up), but starting in Oracle 11, the SELECT ... PIVOT feature could help you.
    i can get output like below through several joins, however i was hoping to condense each "id" into a single line... Condensing the output, so that there's only one line for each puid, sounds like a job for "GROUP BY puid":
    WITH     got_r_num     AS
         SELECT     puid
         ,     dt
         ,     ROW_NUMBER () OVER ( PARTITION BY  puid
                                   ORDER BY          seq          -- and/or dt
                           )         AS r_num
         FROM    tablec
    --     WHERE     ...     -- If you need any filtering, put it here
    SELECT       a.puid
    ,       a.task
    ,       MIN (CASE WHEN r.r_num = 1 THEN r.dt END)     AS dt1
    ,       MIN (CASE WHEN r.r_num = 2 THEN r.dt END)     AS dt2
    ,       MIN (CASE WHEN r.r_num = 3 THEN r.dt END)     AS dt3
    ,       MIN (CASE WHEN r.r_num = 4 THEN r.dt END)     AS dt4
    FROM       tablea    a
    JOIN       got_r_num r  ON   a.puid  = r.puid
    GROUP BY  a.puid
    ,            a.task
    ORDER BY  a.puid
    ;I'm guessing that you want the dates arranged by seq; that is, for each puid, the date related to the lowest seq comes first, regardless of whther that date is the earliest date for that puid or not. If that's not what you need, then change the analytic ORDER BY clause.
    This does not assume that the seq values are always consecutive integers (0, 1, 2, ...) for each puid. You can skip, or even duplicate values. However, if the values are always consecutive integers, starting from 0, then you could simplify this. You won't need a sub-query at all; just use seq instead of r_num in the main query.
    Here's the output I got from the query above:
    PUID  TASK  DT1        DT2        DT3        DT4
    id0   task0 12/21/2010 12/22/2010 12/22/2010
    id1   task1 12/23/2010
    id2   task2 12/22/2010 12/23/2010As posted, the query will display the first 4 dts for each puid.
    If there are fewer than 4 dts for a puid, the query will still work. It will leave some columns NULL at the end.
    If there are more than 4 dts for a puid, the query will still work. It will display the first 4, and ignore the others.
    There's nothing special about the number 4; you could make it 3, or 5, or 35, but whatever number you choose, you have to hard-code that many columns into the query, and always get that many columns of output.
    For various ways to deal with a variable number of pivoted coolumns, see the following thread:
    PL/SQL
    This question actually doesn't have anything to do with SQL*Plus; it's strictly a SQL question, and SQL questions are best posted on the "SQL and PL/SQL" forum:
    PL/SQL
    If you're not sure whether a question is more of a SQL question or a SQL*Plus question, then post it on the SQL forum. Many more people pay attention to that forum than to this one.

  • Need help with query that can look data back please help.

    hi guys i have a table like such
    CREATE TABLE "FGL"
        "FGL_GRNT_CODE" VARCHAR2(60),
        "FGL_FUND_CODE" VARCHAR2(60),
        "FGL_ACCT_CODE" VARCHAR2(60),
        "FGL_ORGN_CODE" VARCHAR2(60),
        "FGL_PROG_CODE" VARCHAR2(60),
        "FGL_GRNT_YEAR" VARCHAR2(60),
        "FGL_PERIOD"    VARCHAR2(60),
        "FGL_BUDGET"    VARCHAR2(60)
      )and i have a data like such
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7600','4730','02','11','1','400');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7600','4730','02','10','1','100');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','10','1','0');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','10','14','200');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7600','4730','02','10','14','100');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7600','4730','02','10','2','100');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7470','4730','02','10','2','200');I bascially need to get the total of the budget column. however its not as simple as it sound(well atleast not for me.) the totals carry over to the new period. youll noticed the you have a period column. basically what im saying is that
    fgl_grant_year 10 period 1 = for account 7600 its $100 and $100 for period 2 you see 100 dollars again this is not to be added this is the carried over balance. which remains $100.
    so im trying to write a query that basically does the following.
    im given a period for the sake of this example lets say period 1 i get nothing else. I have to find the greates grant year grab the amount for period 14(which is the total from the previous year) and add it to the amount of the current period. in this case period 1 grnt_year 11
    so the expected outcome should be $700
    240055     240055     7240     4730     02     10     14     200
    240055     240055     7600     4730     02     10     14     100
    240055     240055     7600     4730     02     11     1     400keep in mind that im not given a year just a period.
    any help that you guys can offer would be immensely appreciated. I have been trying to get this to work for over 3 days now.
    finally broke down and put together this post
    Edited by: mlov83 on Sep 14, 2011 8:48 PM

    Frank
    wondering if you can help me modify this sql statement that you provided me with .
    table values have been modified a bit.
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7600','4730','02','11','00','400');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','10','1','100');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','10','1','0');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7600','4730','02','11','1','400');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('360055','360055','7200','4730','02','10','1','400');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('360055','360055','7600','4730','02','10','1','400');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','10','14','200');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7600','4730','02','10','14','100');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','10','14','200');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','10','2','100');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','11','2','600');i need to take one more thing into consideration. if the greatest year has a value on period 00 i need to ignore the period 14 and the current period total would be
    the current period +(current period - greatest year 00)
    hope that makes sense so in other words with the new data above. if i was querying period two of grant year 11. i would end up with $800
    because the greatest year is 11 it contains a period 0 with amount of $400 so my total should be
    period 2 amount $ 600
    period 0 amount $ 400 - period 2 amount of $600 = 200
    600+200 = $800
    if i query period 1 of grant 360055 i would just end up with 800 of grnt year 10.
    i have tried to modify that query you supplied to me with no luck. I have tried for several day but im embarrased to say i just can get it to do what im trying to do .
    can you please help me out.
    Miguel

  • Query off of Oracle using WinSql - Need help with query

    I am trying to query off of Oracle using program WinSql.
    I have a table(tticpr200110) that has the following sample data:
    ITEM     CODE     T$AMNT
    23500076 ACL     .0049
    23500076 APM     0
    23500076 APO     .0093
    23500076 EXP     .0001
    23500076 RES     .0072
    and what I want it to look like is:
    ITEM     ACL     APM     APO     EXP     RES
    23500076     0.0049     0     0.0093     0.0001     0.0072
    (actually I need the last 2 columns added together to be MATL-but can deal with that down the road).
    Seems simple enough, but I don't know to put into the columns.
    Any help would be GREATLY appreciated as soon as possible would be even better.

    My table - tticpr200110 when it runs I get the following sample data for part number 23500076:
    The first coloumn ITEM is the part number.
    The second column CODE is 1 of 5 different cost codes
    The third column is the cost for that code for that part.
    ITEM CODE AMNT
    23500076 ACL 0.0049
    23500076 APM 0.0000
    23500076 APO 0.0093
    23500076 EXP 0.0001
    23500076 RES 0.0072
    I want to make a query that makes the data look like this:
    ITEM ACL APM APO EXP RES
    23500076 0.0049 0.0000 0.0093 0.0001 0.0072
    (similar to a pivot table in excel or acess)
    I hope this helps better.
    Thanks!

  • Need help with Query to determine Credit Memos and Invoices

    Hi All
    Thanks for all the help here.
    I need a query to determine any credits or invoices issued within a given period.
    OINV and ORIN with UNION ALL?
    Please advise any help.
    Thank you!

    Hi Daniel,
    Please check below Query.
    SELECT T0.[DocNum] as 'Invice No', T0.[DocDate] as 'Invoice Date', T0.[CardName] as 'Invoiced Customer', T3.[DocNum] as 'Credit Memo No', T3.[DocDate] as 'Credit Mamo Date', T3.[CardName] as 'Credit Memo Customer' FROM OINV T0  LEFT JOIN INV1 T1 ON T0.[DocEntry] = T1.[DocEntry] LEFT JOIN RIN1 T2 ON T2.[BaseEntry] = T1.[DocEntry] AND T2.[BaseLine] =  T1.[LineNum] LEFT JOIN ORIN T3 ON T2.[DocEntry] = T3.[DocEntry] WHERE T0.[DocDate]  >=[%3]  AND   T0.[DocDate] <=[%4]
    Hope this helps
    Regards::::
    Atul Chakraborty

  • Need Help With Query Using Aggregation

    If I have a table, defined like this:
    CREATE TABLE range_test
    range_id NUMBER(20) NOT NULL,
    grade CHAR(1) NOT NULL,
    lower_bound_of_range NUMBER(5,2) NOT NULL,
    upper_bound_of_range NUMBER(5,2) NOT NULL,
    received_date_time_stamp TIMESTAMP DEFAULT SYSTIMESTAMP NOT NULL
    And I wanted to query the table to find the range associated with the last inserted row for each 'grade' (e.g. 'A', 'B', 'C', etc), how would I go about that?
    I want something like the following, but I know that this won't work right:
    SELECT
    grade,
    lower_bounding_of_range,
    upper_bounding_of_range,
    max(received_date_time_stamp)
    FROM
    range_test GROUP BY received_date_time_stamp;
    Thanks for your help. . .I'm frustrating myself with this one and I think it should be possible without having to use PL/SQL (i.e. SQL aggregate functions or sub-queries should work).

    Perhaps something along the lines of...
    SQL> ed
    Wrote file afiedt.buf
      1  select deptno, empno, ename, hiredate
      2  from emp
      3* order by deptno, empno
    SQL> /
        DEPTNO      EMPNO ENAME      HIREDATE
            10       7782 CLARK      09-JUN-1981 00:00:00
            10       7839 KING       17-NOV-1981 00:00:00
            10       7934 MILLER     23-JAN-1982 00:00:00
            20       7369 SMITH      17-DEC-1980 00:00:00
            20       7566 JONES      02-APR-1981 00:00:00
            20       7788 SCOTT      19-APR-1987 00:00:00
            20       7876 ADAMS      23-MAY-1987 00:00:00
            20       7902 FORD       03-DEC-1981 00:00:00
            30       7499 ALLEN      20-FEB-1981 00:00:00
            30       7521 WARD       22-FEB-1981 00:00:00
            30       7654 MARTIN     28-SEP-1981 00:00:00
            30       7698 BLAKE      01-MAY-1981 00:00:00
            30       7844 TURNER     08-SEP-1981 00:00:00
            30       7900 JAMES      03-DEC-1981 00:00:00
    14 rows selected.
    SQL> ed
    Wrote file afiedt.buf
      1  select deptno, empno, ename, hiredate
      2  from (
      3        select deptno, empno, ename, hiredate
      4              ,row_number() over (partition by deptno order by hiredate desc) as rn
      5        from emp
      6       )
      7  where rn = 1
      8* order by deptno, empno
    SQL> /
        DEPTNO      EMPNO ENAME      HIREDATE
            10       7934 MILLER     23-JAN-1982 00:00:00
            20       7876 ADAMS      23-MAY-1987 00:00:00
            30       7900 JAMES      03-DEC-1981 00:00:00
    SQL>

  • Need help with Querying XML - XQuery

    Hey guys, im new to this stuff so  I gained some knowledge from internet but I'm running is some problem that I'll explain below. I have XML like:  
    <?xml version="1.0" encoding="iso-8859-1"?>
    <star:ShowLaborOperations xmlns:star="http://www.starstandard.org/STAR/5" releaseID="5.4.4">
    <star:ApplicationArea>
    <star:Sender>
    <star:CreatorNameCode>AD</star:CreatorNameCode>
    <star:SenderNameCode>DDDD</star:SenderNameCode>
    <star:SystemVersion>AD2.0</star:SystemVersion>
    </star:Sender>
    <star:CreationDateTime>2011-05-06T12:51:33Z</star:CreationDateTime>
    <star:BODID>A29BF24F-F68E-5CE5-E040-35A54242A0C</star:BODID>
    <star:Destination>
    <star:DestinationNameCode>AD</star:DestinationNameCode>
    </star:Destination>
    </star:ApplicationArea>
    <star:ShowLaborOperationsDataArea>
    <star:Show>
    <oagis:ResponseCriteria xmlns:oagis="http://www.openapplications.org/oagis/9">
    <oagis:ChangeStatus>
    <oagis:Description>Changes</oagis:Description>
    </oagis:ChangeStatus>
    </oagis:ResponseCriteria>
    </star:Show>
    <star:LaborOperations>
    <star:LaborOperationsHeader>
    <star:RequestCode>Changes</star:RequestCode>
    <star:LaborOperationsHeaderBase>
    <star:DocumentIdentificationGroup>
    <star:DocumentIdentification>
    <star:DocumentID>ShowOperationCode20110506050532TY</star:DocumentID>
    </star:DocumentIdentification>
    </star:DocumentIdentificationGroup>
    </star:LaborOperationsHeaderBase>
    <star:LaborOperationCodes/>
    </star:LaborOperationsHeader>
    <star:LaborOperationsDetail>
    <star:LaborOperationID>001020</star:LaborOperationID>
    <star:MajorGroupID>00</star:MajorGroupID>
    <star:ComponentGroupID>01</star:ComponentGroupID>
    <star:LaborOperationDescription>GAS TANK FILL</star:LaborOperationDescription>
    <star:LaborActionCode>OTH</star:LaborActionCode>
    <star:LaborOperationsChangeStatus>U</star:LaborOperationsChangeStatus>
    <star:Combinations>
    <star:VehicleGroupLaborAllowance>
    <star:VehicleIdentificationGroup>
    <star:VehicleGroupID>JTN</star:VehicleGroupID>
    <star:VehicleID>JJXB0</star:VehicleID>
    </star:VehicleIdentificationGroup>
    <star:ChangeStatus>A</star:ChangeStatus>
    <star:LaborAllowanceMeasure unitCode="hour">0.0</star:LaborAllowanceMeasure>
    <star:ChargeHoursIndicator>false</star:ChargeHoursIndicator>
    </star:VehicleGroupLaborAllowance>
    <star:VehicleGroupLaborAllowance>
    <star:VehicleIdentificationGroup>
    <star:VehicleGroupID>JTM</star:VehicleGroupID>
    <star:VehicleID>ZF32V</star:VehicleID>
    </star:VehicleIdentificationGroup>
    <star:ChangeStatus>U</star:ChangeStatus>
    <star:LaborAllowanceMeasure unitCode="hour">0.6</star:LaborAllowanceMeasure>
    <star:ChargeHoursIndicator>true</star:ChargeHoursIndicator>
    </star:VehicleGroupLaborAllowance>
    </star:Combinations>
    </star:LaborOperationsDetail>
    </star:LaborOperations>
    </star:ShowLaborOperationsDataArea>
    </star:ShowLaborOperations>
    and I wanna be able to see the following result: 
    <LaborOperationsDetail xmlns="http://www.starstandard.org/STAR/5">
    <LaborOperationID>001020</LaborOperationID>
    <MajorGroupID>00</MajorGroupID>
    <ComponentGroupID>01</ComponentGroupID>
    <LaborOperationDescription>GAS TANK FILL</LaborOperationDescription>
    <LaborActionCode>OTH</LaborActionCode>
    <LaborOperationsChangeStatus>U</LaborOperationsChangeStatus>
    <Combinations>
    <VehicleGroupLaborAllowance>
    <VehicleIdentificationGroup>
    <VehicleGroupID>JTN</VehicleGroupID>
    <VehicleID>JJXB0</VehicleID>
    </VehicleIdentificationGroup>
    <ChangeStatus>A</ChangeStatus>
    <LaborAllowanceMeasure unitCode="hour">0.0</LaborAllowanceMeasure>
    <ChargeHoursIndicator>false</ChargeHoursIndicator>
    </VehicleGroupLaborAllowance>
    </Combinations>
    </LaborOperationsDetail>
    for which I'm writing the following query 
    SELECT OpCodeXMLCol.query('
    declare default element namespace "http://www.starstandard.org/STAR/5";
    /ShowLaborOperations/ShowLaborOperationsDataArea/LaborOperations/LaborOperationsDetail[Combinations/VehicleGroupLaborAllowance/VehicleIdentificationGroup/VehicleGroupID="JTN"][LaborOperationID="001020"]
    -- specified [LaborOperationID="001020"] because there are multiple <LabrOperationDetial> ') as x
    FROM XMLData.dbo.OpCodeData
    where [ID] = 3 -- primary key for that row containing XML in first snippet
    but I'm getting both nodes for <VehicleIdentificatonGroup> whereas I expect to see one containing <VehicleGroupID>JTN</VehicleGroupID> as per filter in query. Please help

    The closest thing which makes sense:
    DECLARE @Data XML = N'
    <star:ShowLaborOperations xmlns:star="http://www.starstandard.org/STAR/5" releaseID="5.4.4">
    <star:ApplicationArea>
    <star:Sender>
    <star:CreatorNameCode>AD</star:CreatorNameCode>
    <star:SenderNameCode>DDDD</star:SenderNameCode>
    <star:SystemVersion>AD2.0</star:SystemVersion>
    </star:Sender>
    <star:CreationDateTime>2011-05-06T12:51:33Z</star:CreationDateTime>
    <star:BODID>A29BF24F-F68E-5CE5-E040-35A54242A0C</star:BODID>
    <star:Destination>
    <star:DestinationNameCode>AD</star:DestinationNameCode>
    </star:Destination>
    </star:ApplicationArea>
    <star:ShowLaborOperationsDataArea>
    <star:Show>
    <oagis:ResponseCriteria xmlns:oagis="http://www.openapplications.org/oagis/9">
    <oagis:ChangeStatus>
    <oagis:Description>Changes</oagis:Description>
    </oagis:ChangeStatus>
    </oagis:ResponseCriteria>
    </star:Show>
    <star:LaborOperations>
    <star:LaborOperationsHeader>
    <star:RequestCode>Changes</star:RequestCode>
    <star:LaborOperationsHeaderBase>
    <star:DocumentIdentificationGroup>
    <star:DocumentIdentification>
    <star:DocumentID>ShowOperationCode20110506050532TY</star:DocumentID>
    </star:DocumentIdentification>
    </star:DocumentIdentificationGroup>
    </star:LaborOperationsHeaderBase>
    <star:LaborOperationCodes/>
    </star:LaborOperationsHeader>
    <star:LaborOperationsDetail>
    <star:LaborOperationID>001020</star:LaborOperationID>
    <star:MajorGroupID>00</star:MajorGroupID>
    <star:ComponentGroupID>01</star:ComponentGroupID>
    <star:LaborOperationDescription>GAS TANK FILL</star:LaborOperationDescription>
    <star:LaborActionCode>OTH</star:LaborActionCode>
    <star:LaborOperationsChangeStatus>U</star:LaborOperationsChangeStatus>
    <star:Combinations>
    <star:VehicleGroupLaborAllowance>
    <star:VehicleIdentificationGroup>
    <star:VehicleGroupID>JTN</star:VehicleGroupID>
    <star:VehicleID>JJXB0</star:VehicleID>
    </star:VehicleIdentificationGroup>
    <star:ChangeStatus>A</star:ChangeStatus>
    <star:LaborAllowanceMeasure unitCode="hour">0.0</star:LaborAllowanceMeasure>
    <star:ChargeHoursIndicator>false</star:ChargeHoursIndicator>
    </star:VehicleGroupLaborAllowance>
    <star:VehicleGroupLaborAllowance>
    <star:VehicleIdentificationGroup>
    <star:VehicleGroupID>JTM</star:VehicleGroupID>
    <star:VehicleID>ZF32V</star:VehicleID>
    </star:VehicleIdentificationGroup>
    <star:ChangeStatus>U</star:ChangeStatus>
    <star:LaborAllowanceMeasure unitCode="hour">0.6</star:LaborAllowanceMeasure>
    <star:ChargeHoursIndicator>true</star:ChargeHoursIndicator>
    </star:VehicleGroupLaborAllowance>
    </star:Combinations>
    </star:LaborOperationsDetail>
    </star:LaborOperations>
    </star:ShowLaborOperationsDataArea>
    </star:ShowLaborOperations>
    WITH XMLNAMESPACES ( DEFAULT 'http://www.starstandard.org/STAR/5' )
    SELECT LaborOperationsDetail.query('.'),
    VehicleGroupLaborAllowance.query('.')
    FROM @Data.nodes('/ShowLaborOperations/ShowLaborOperationsDataArea/LaborOperations/LaborOperationsDetail') A ( LaborOperationsDetail )
    CROSS APPLY LaborOperationsDetail.nodes('Combinations/VehicleGroupLaborAllowance[VehicleIdentificationGroup/VehicleGroupID="JTN"]') B ( VehicleGroupLaborAllowance );
    Otherwise we need to destruct and rebuild the XML. This in this case imho better done with XSLT.

  • Need help with query from .csv file

    I am trying to import a csv file with only 1 column in it.
    The column will only contain a 9 digit ID number. I want to read
    the file then use the contents to query a table to get the names
    and other information and display it. Here is what I have so far:
    <cffile action="read" file="#form.FiletoUpload#"
    variable="csvfile">
    <cfloop index="index" list="#csvfile#">
    <cfquery name="massimport" datasource="data1">
    SELECT * FROM IDTable
    WHERE CardNumber = ('#csvfile#')
    </cfquery>
    </cfloop>
    <cfoutput>#Name# #ID# #Site#</cfoutput>
    I get no errors but I am not getting any results. Just a
    blank page. Does anyone know how to query directly from a csv
    import? Thanks.

    You need to convert your file to a list somehow. Not sure if
    this is the most efficient way but, you can use the cfhttp tag to
    produce a query. Then your where clause becomes,
    where cardnumber in (#quotedvaluelist(query.column)#)
    and you won't need a loop.

  • Need help with query for converting columns to rows

    Hello,
    I know this is a very common question asked in the forum. I have searched regading this, i did find some threads, but i was not able to achieve what i require from the answers posted. So anybody please help me.
    I have a table which is having multiple columns as follows:
    Insert into table_1 (X,Y,Z,A,B,C,D,E,F,G,H,I) values (0,0,2,0,0,1,3,0,0,0,0,0);I want to convert the result into a two column, multiple rows i.e., I want the result as follows:
    Col1 Col2
    X      0
    Y     0
    Z      2
    A     0
    B     0
    C     1
    D     3
    E     0
    F     0
    G     0
    H     0
    I      0Please anybody help me in writing the query for this..

    Is this what you are expecting:
    SQL> WITH T AS
      2  (
      3  SELECT 0 X, 0 Y, 2 Z, 0 A, 0 B, 1 C, 3 D, 0 E, 0 F, 0 G, 0 H, 0 I FROM DUAL
      4  )
      5  SELECT  'X' col1, X col2 FROM T
      6  UNION ALL
      7  SELECT  'Y' col1, Y col2 FROM T
      8  UNION ALL
      9  SELECT  'Z' col1, Z col2 FROM T
    10  UNION ALL
    11  SELECT  'A' col1, A col2 FROM T
    12  UNION ALL
    13  SELECT  'B' col1, B col2 FROM T
    14  UNION ALL
    15  SELECT  'C' col1, C col2 FROM T
    16  UNION ALL
    17  SELECT  'D' col1, D col2 FROM T
    18  UNION ALL
    19  SELECT  'E' col1, E col2 FROM T
    20  UNION ALL
    21  SELECT  'F' col1, F col2 FROM T
    22  UNION ALL
    23  SELECT  'G' col1, G col2 FROM T
    24  UNION ALL
    25  SELECT  'H' col1, H col2 FROM T
    26  UNION ALL
    27  SELECT  'I' col1, I col2 FROM T
    28  /
    C       COL2                                                                   
    X          0                                                                   
    Y          0                                                                   
    Z          2                                                                   
    A          0                                                                   
    B          0                                                                   
    C          1                                                                   
    D          3                                                                   
    E          0                                                                   
    F          0                                                                   
    G          0                                                                   
    H          0                                                                   
    C       COL2                                                                   
    I          0                                                                   
    12 rows selected.

  • Need help with querying users

    It only displays the correct amount of members when I queried only one group like this:
    select SMS_R_USER.ResourceID,SMS_R_USER.ResourceType,SMS_R_USER.Name,SMS_R_USER.UniqueUserName,SMS_R_USER.WindowsNTDomain from SMS_R_User where SMS_R_User.SecurityGroupName = "domain\\security group1"
    When I tried for multiple groups like shown below, it shows 0 member. I received no error for the query though it is obviously wrong. 
    select SMS_R_USER.ResourceID,SMS_R_USER.ResourceType,SMS_R_USER.Name,SMS_R_USER.UniqueUserName,SMS_R_USER.WindowsNTDomain from SMS_R_User where SMS_R_User.SecurityGroupName = "domain\\security group1" and SMS_R_User.SecurityGroupName = "domain\\security
    group2" and SMS_R_User.SecurityGroupName = "domain\\security group3"
    Please check and help me correct it so I can get all members in one collection.
    Thanks

    Hi,
    If you look to query the amount of members in all the groups you define, use OR instead of AND.
    When you use AND, you define that the result must be a member of group1 AND group2 AND group3. You should use OR to get the members of the groups, even though they're just a member of one of them.
    select SMS_R_USER.ResourceID,SMS_R_USER.ResourceType,SMS_R_USER.Name,SMS_R_USER.UniqueUserName,SMS_R_USER.WindowsNTDomain from SMS_R_User where SMS_R_User.SecurityGroupName = "domain\\security group1" or SMS_R_User.SecurityGroupName = "domain\\security
    group2" or SMS_R_User.SecurityGroupName = "domain\\security group3"
    All the best, Jesper Hassing - MCTS SCCM 2012 - MCSA 2012 Server - MCP

  • Need help with querying pl/sql collections

    hi all,
    i have a requirement wherein i look thru a number of records and then updates. then i need to check if these records were successfully updated. i have the following code but it doesn't work on the part where i query the collection.
    declare
      type ap_invoices_all_tbl is table of ap_invoices_all%rowtype;
      ap_invoices_all_rec ap_invoices_all_tbl;
      cursor cai is
        select *
          from ap_invoices_all ai
         where source = 'XXX';
    begin
      open cai;
      fetch cai bulk collect into ap_invoices_all_rec;
      for i in 1..ap_invoices_all_rec.count loop
        begin
        dbms_output.put_line('Invoice Status: ' || ap_invoices_pkg.get_approval_status( ap_invoices_all_rec(i).invoice_id, ap_invoices_all_rec(i).invoice_amount, ap_invoices_all_rec(i).payment_status_flag, ap_invoices_all_rec(i).invoice_type_lookup_code));
        exception
          when no_data_found then
            null;
        end;
      end loop;
      for j in ( select * from ap_invoices_all ai
                  where invoice_id in ( select invoice_id
                                          from ap_invoices_all_rec ))
      loop
        dbms_output.put_line('Invoice Number: ' || j.invoice_num);
      end loop;
    end;i do understand that i cannot use select statement directly on a collection but i just wanted to show what i'm trying to achieve.
    any suggestions on what i should do?
    thanks
    allen

    You can not use locally defined collection(pl/sql) in SELECT statement directly, instead use Objects defined in schema.
    For example:
    SQL> CREATE OR REPLACE TYPE emp_rec IS OBJECT (
      2                      v_sal    NUMBER(7,2),
      3                      v_name   VARCHAR2(35),
      4                      v_empno  NUMBER(4),
      5                      v_deptno NUMBER(2)
      6                      )
      7  ;
      8  /
    Type created.
    SQL> CREATE OR REPLACE TYPE emp_tab IS TABLE OF emp_rec;
      2  /
    Type created.
    SQL> CREATE OR REPLACE TYPE dept_rec IS OBJECT (
      2                      v_deptno NUMBER,
      3                      v_dname VARCHAR2(50)
      4                      )
      5  ;
      6  /
    Type created.
    SQL> CREATE OR REPLACE TYPE dept_tab IS TABLE OF dept_rec;
      2  /
    Type created.
    SQL> CREATE OR REPLACE TYPE emp_dept_rec IS
      2                     OBJECT (
      3                      v_sal     NUMBER,
      4                      v_name     VARCHAR2(35),
      5                      v_deptname VARCHAR2(30)
      6                      );
      7  /
    Type created.
    SQL> CREATE OR REPLACE TYPE emp_dept_tab_type IS TABLE OF emp_dept_rec;
      2  /
    Type created.
    SQL> set serverout on
    SQL> DECLARE
      2    l_emp_dept_tab emp_dept_tab_type; --emp_dept_tab_type declared in database
      3    l_emp_tab      emp_tab; --emp_tab declared in database
      4    l_dept_tab     dept_tab; --dept_tab declared in database
      5 
      6    CURSOR e1 IS
      7      SELECT emp_rec(sal, ename, empno, deptno) FROM emp; --Note the type casting here
      8 
      9    CURSOR d1 IS
    10      SELECT dept_rec(deptno, dname) FROM dept; --Note the type casting here
    11  BEGIN
    12    OPEN e1;
    13 
    14    FETCH e1 BULK COLLECT
    15      INTO l_emp_tab;
    16 
    17    OPEN d1;
    18 
    19    FETCH d1 BULK COLLECT
    20      INTO l_dept_tab;
    21 
    22    SELECT CAST(MULTISET (SELECT em.v_sal, em.v_name, dep.v_dname
    23                   FROM TABLE(l_emp_tab) em, TABLE(l_dept_tab) dep
    24                  WHERE em.v_deptno = dep.v_deptno) AS emp_dept_tab_type)
    25      INTO l_emp_dept_tab
    26      FROM DUAL;
    27    FOR i IN 1 .. l_emp_dept_tab.COUNT LOOP
    28      dbms_output.put_line(l_emp_dept_tab(i)
    29                           .v_sal || '--' || l_emp_dept_tab(i)
    30                           .v_name || '--' || l_emp_dept_tab(i).v_deptname);
    31    END LOOP;
    32 
    33  END;
    34  /
    1300--MILLER--ACCOUNTING
    5000--KING--ACCOUNTING
    2450--CLARK--ACCOUNTING
    3000--FORD--RESEARCH
    1100--ADAMS--RESEARCH
    3000--SCOTT--RESEARCH
    2975--JONES--RESEARCH
    800--SMITH--RESEARCH
    950--JAMES--SALES
    1500--TURNER--SALES
    2850--BLAKE--SALES
    1250--MARTIN--SALES
    1250--WARD--SALES
    1600--ALLEN--SALES
    PL/SQL procedure successfully completed.
    SQL>

  • NEED HELP WITH QUERY, NEED NEWEST RECORD ONLY

    Hi all,
    Here goes,
    I have an assingment in which i need to find the agents who allow the footballers to break the rules.
    So far i have 41 results, in which there is 4 agents and 24 footballers, and the same footballer has broken more than one rule or the rule more than once.
    What i now need is to arrange so that each footballer on shows up once no matter how many times they have broken the rules.
    i have
    SELECT
    t.transfer_time || ' ' || a.first_name || ' ' || a.last_name || ' ' || f.first_name || ' ' || f.last_name || ' ' || f.footballer_id || ' ' || t.transfer_id
    FROM
    agents a, transfers t, footballers f, footballers_fees fo
    WHERE
    a.agent_id = t.broker_id
    AND
    t.footballer_id = f.footballer_id
    AND
    f.footballer_id = fo.footballer_id
    AND
    (RULE 1 BROKEN AND RULE 2 BROKEN
    OR
    RULE 1 BROKEN AND RULE 2 NOT BROKEN
    OR
    RULE 1 NOT BROKEN AND RULE 2 BROKEN)
    GROUP BY
    t.transfer_time || ' ' || a.first_name || ' ' || a.last_name || ' ' || f.first_name || ' ' || f.last_name || ' ' || f.footballer_id || ' ' || t.transfer_id
    ORDER BY
    t.transfer_time || ' ' || a.first_name || ' ' || a.last_name || ' ' || f.first_name || ' ' || f.last_name || ' ' || f.footballer_id || ' ' || t.transfer_id
    (I havent typed out the SQL for the rules 1 and 2 but i know it works)
    Now i need to show only each footballer once whether they have broken either rule and more than once or not.
    I have been staring at the screen for near enough 10 hours and any help or ideas would be greatly appreciated
    Thanks all :)

    884080 wrote:
    Hi all,
    Here goes,
    I have an assingment in which i need to find the agents who allow the footballers to break the rules.
    So far i have 41 results, in which there is 4 agents and 24 footballers, and the same footballer has broken more than one rule or the rule more than once.
    What i now need is to arrange so that each footballer on shows up once no matter how many times they have broken the rules.
    i have
    SELECT
    t.transfer_time || ' ' || a.first_name || ' ' || a.last_name || ' ' || f.first_name || ' ' || f.last_name || ' ' || f.footballer_id || ' ' || t.transfer_id
    FROM
    agents a, transfers t, footballers f, footballers_fees fo
    WHERE
    a.agent_id = t.broker_id
    AND
    t.footballer_id = f.footballer_id
    AND
    f.footballer_id = fo.footballer_id
    AND
    (RULE 1 BROKEN AND RULE 2 BROKEN
    OR
    RULE 1 BROKEN AND RULE 2 NOT BROKEN
    OR
    RULE 1 NOT BROKEN AND RULE 2 BROKEN)
    GROUP BY
    t.transfer_time || ' ' || a.first_name || ' ' || a.last_name || ' ' || f.first_name || ' ' || f.last_name || ' ' || f.footballer_id || ' ' || t.transfer_id
    ORDER BY
    t.transfer_time || ' ' || a.first_name || ' ' || a.last_name || ' ' || f.first_name || ' ' || f.last_name || ' ' || f.footballer_id || ' ' || t.transfer_id
    (I havent typed out the SQL for the rules 1 and 2 but i know it works)
    Now i need to show only each footballer once whether they have broken either rule and more than once or not.
    I have been staring at the screen for near enough 10 hours and any help or ideas would be greatly appreciated
    Thanks all :)Realize that we don't have your tables or data, so we can't run, test, or improve your SQL.
    so what exactly do you expect from us?

  • Need help with query that uses 'SELECT INTO'

    Hi guys,
    I am trying to duplicate the values of a table to another by using the script below:
    ACCEPT TBSNAME           CHAR PROMPT 'Tablespace name>'
    PROMPT Connect As System
    Connect system
    CREATE TABLE FREESPACE
         TABLESPACE_NAME          VARCHAR(20)          NOT NULL,
              CONSTRAINT FREESPACE_PKEY PRIMARY KEY(TABLESPACE_NAME),
         TOTAL_FREE_STORAGE     NUMBER(10)          NOT NULL
    ) TABLESPACE USERS;
    SELECT     TABLESPACE_NAME,
              SUM(BLOCKS) TOTBLOCKS
    INTO      FREESPACE
    FROM      SYS.DBA_FREE_SPACE
    WHERE      TABLESPACE_NAME = UPPER('&TBSNAME')
    GROUP BY TABLESPACE_NAME;
    However, when I execute this script, I was prompted with the 'missing keyword' error which happens at the third line of the select statment. Any idea what's missing here?
    Thanks in advance.

    If you mean "fill up the table FREESPACE" by using "select...into..." then it is totally wrong. You cannot do it in plsql also.
    Use this:
    insert into freespace(tablespace_name,total_free_storage)
    SELECT TABLESPACE_NAME,SUM(BLOCKS) TOTBLOCKS
    FROM SYS.DBA_FREE_SPACE
    WHERE TABLESPACE_NAME = UPPER('&TBSNAME')
    GROUP BY TABLESPACE_NAME;
    Message was edited by:
    Yas

  • Need help with query for OITW

    I want to query a list that gives me all OnHand quantities for the Warehouses in one line per item:
    Item, Qty Whs1, Qty Whs2 ...
    Item1, Qty1_1, Qty1_2 ...
    Item2, Qty2_1, Qty2_2 ...
    Could somebody put me in the right direction?
    Thanks
    Franz

    Try this:
    SELECT P.Itemcode, T.ItemName,
    (Select U_NF_LagPlatz1 from OITW where WhsCode = 'NFE-1' and itemcode = T.Itemcode),
    (Select U_NF_LagPlatz2 from OITW where WhsCode = 'NFE-1' and itemcode = T.Itemcode),
        [NFE-1] AS Q1, [2] AS Q2, [3] AS Q3, [4] AS Q4,
        [5] AS Q5, [6] AS Q6, [7] AS Q7, [8] AS Q8,
        [9] AS Q9, [10] AS Q10
    FROM dbo.OITM T
    INNER JOIN
    (select Itemcode,OnHand, Whscode from oitw) s
    PIVOT
        sum(onhand)
        FOR whscode IN ([NFE-1],[2],[3],[4],[5],[6],[7],[8],[9],[10])
    ) p ON P.ItemCode = T.ItemCode
    ORDER BY P.[Itemcode]
    Regards,
    Bala
    Edited by: Balakumar Viswa on Jul 26, 2010 3:06 PM

  • Need help with query join...

    Hi all, i have the below query, it has too many where clauses and want to seperate it into joins perhaps, how can i do this please suggest some syntax.
    Thanks,
    Alex
    CODE:
    “select surname,award.name as award_name,module.name as module_name,attemptno as attempt_no from student,award,studentaward,module,studentenrollment where studentenrollment.attemptno = 2 and studentenrollment.studentid = student.studentid and studentenrollment.moduleid = module.moduleid and studentaward.studentid = student.studentid and studentaward.awardid = award.awardid”

    select surname,award.name as award_name,module.name as module_name,attemptno as attempt_no
    from student
    join studentaward on studentaward.studentid = student.studentid
    join award on studentaward.awardid = award.awardid
    join studentenrollment on studentenrollment.studentid = student.studentid
    join module on studentenrollment.moduleid = module.moduleid
    where studentenrollment.attemptno = 2

Maybe you are looking for

  • Directory structure for servlets and webservices in one application

    hi, Can any one help me for creating servlets and webservices in one application and deploying in Jboss 4.2.0. I want to know exactly what is the directory structure for creating this application and what are the additional .xml files for deploying t

  • How to link to an R3 system(not sure where it goes sorry)

    I was handed a netweaver04 installation and now I have to complete it. The Portal is up but I need to point it to the correct R3 system and then get the Iviews loaded and working. Anybody got any clues on where to go with this one. Thanks in Advance

  • Web service response too big to handle

    Hi, We are implementing web service in PTools 8.46. It is synchronous OUtbound. When we generate the request, the response for the same is too big to handle. The app Engine which sends the SYNCREQUEST goes to 'Processing' status and remains that way.

  • Sun Fire V490 dropping network connnections

    Hi We are having some issues on v490. Network connections are getting drop and users are getting given below error remote host : Connection reset by peer aocdbs02a:root# fmdump -v -u 5b137743-2acf-ceb5-bfde-f4604e3f6d4f TIME UUID SUNW-MSG-ID Nov 02 1

  • SCCM 2012 R2 - Software metering Reports Parameters Value not appear to choice

    Hello Every Body I hope to get answer as soon as possible I have SCCM 2012 R2 & SQL Server 2012 SP1, my problem is ( all software metering Reports Parameters Values Not appear so I cannot select Note:- ( All parameters Available Value set to Get Valu