SQL Select - Is this logic valid?

Hello guys,
I was wondering if anyone can tell me if my query is valid or not? [This is an exercice, it's not something really critical].
Let suppose I have 2 tables (Organizations and Employees). I would like to retrieve all the organizations with only one fake person under.
CREATE TABLE ORGANIZATIONS
  id_organization number(10) primary key,
  name            varchar2(100) not null
CREATE TABLE EMPLOYEES
  id_employee     number(10) primary key,
  id_organization number(10),
  name            varchar2(100) not null,
  is_fake         char(1)
insert into organizations values(1, 'Org 1');
insert into organizations values(2, 'Org 2');
insert into employees values(1, 1, 'Emp 1', 1);
insert into employees values(2, 1, 'Emp 2', 0);
insert into employees values(3, 1, 'Emp 3', 0);Is this query correct ?
I mean, does this query returns the correct result? All the organization with only one fake person under?
    SELECT a.id_organization, b.id_employee
      FROM ORGANIZATIONS a
      LEFT JOIN EMPLOYEES b ON a.id_organization = b.id_organization
     WHERE b.is_fake = 1;Thanks,

Hi,
Thanks for posting the sample data in such a useful form!
Don't forget to post the results you want from that data.
Does your problem cioncern finidng out if there is exactly one fake in a given organization, as there is in id_organization=1? If so, maybe you should add some more data so you can compare results with an organization that has more than one fake employee, like this:
insert into employees (id_employee,     id_organization,     name,          is_fake)
     values           (21,           2,                'Fake 21',      '1');
insert into employees (id_employee,     id_organization,     name,          is_fake)
     values           (22,           2,                'Fake 22',      '1');
insert into employees (id_employee,     id_organization,     name,          is_fake)
     values           (23,           2,                'Real 23',      '0');If someone posts a solution, and it doesn't work, point out exactly where it is wrong, and explain how you get the right results in those places.
What is wrong with Karthick's solution?

Similar Messages

  • Need SQL code for this logic - -  From Serial and To serial no.

    In Forms 4.5 Screen I have two text boxes where i will be entering From Serial No
    and to serial no.
    I want the code which will check whether any number in between these from and to serial exists in a table or not ?
    For Example
    Select * from t; -- contains
    serial number
    321-456-789
    123-456-654
    321-569-986
    321-569-987
    When I enter from Serial no 321-456-789 and to serial no as 321-456-789.. I should get a message sayinig that 321-456-789 exists.
    When I enter from Serial no 321-569-986 and to serial no as 321-569-988.
    I should get a message sayinig that 321-456-986 exists.
    I should get a message sayinig that 321-456-987 exists.
    I should get a message sayinig that 321-456-988 not exists.
    is it possible with a SQL query or do we need to go for procedure or temp table ?
    If anybody ahving similar code please post it here.
    Thanks in Advance
    Devender

    Hi Devender,
    Try this :
    SQL> select * from t;
    SN
    321-456-789
    123-456-654
    321-569-986
    321-569-987
    SQL> var sn1 varchar2(11)
    SQL> exec :sn1 := '321-569-986'
    Procédure PL/SQL terminée avec succès.
    SQL> var sn2 varchar2(11)
    SQL> exec :sn2 := '321-569-988'
    Procédure PL/SQL terminée avec succès.
    SQL>1  select a.sn, decode(t.sn,null,'does not exists','already exists')
      2  from
      3  (select substr(replace(:sn1,'-','')+rownum-1,1,3)||'-'
      4        ||substr(replace(:sn1,'-','')+rownum-1,4,3)||'-'
      5        ||substr(replace(:sn1,'-','')+rownum-1,7,3) as sn
      6  from (select level
      7        from dual
      8        connect by level <= (replace(:sn2,'-','')-replace(:sn1,'-',''))+1
      9       )
    10  )a,
    11  t
    12* where a.sn=t.sn(+)
    SQL> /
    SN                            DECODE(T.SN,NUL
    321-569-986                   already exists
    321-569-987                   already exists
    321-569-988                   does not exists
    SQL> exec :sn1 := '321-456-789'
    Procédure PL/SQL terminée avec succès.
    SQL> exec :sn2 := '321-456-789'
    Procédure PL/SQL terminée avec succès.
    SQL> l
      1  select a.sn, decode(t.sn,null,'does not exists','already exists')
      2  from
      3  (select substr(replace(:sn1,'-','')+rownum-1,1,3)||'-'
      4        ||substr(replace(:sn1,'-','')+rownum-1,4,3)||'-'
      5        ||substr(replace(:sn1,'-','')+rownum-1,7,3) as sn
      6  from (select level
      7        from dual
      8        connect by level <= (replace(:sn2,'-','')-replace(:sn1,'-',''))+1
      9       )
    10  )a,
    11  t
    12* where a.sn=t.sn(+)
    SQL> /
    SN                            DECODE(T.SN,NUL
    321-456-789                   already exists
    SQL> Nicolas.

  • Need sql querry for this logic

    Hi,
    Edited by: 937506 on Jun 10, 2012 7:35 AM

    937506 wrote:
    Hi,
    I have table like this,based on this table data i need one column for example "Value" based on this condition,
    KEY     A_VAL     ETA_VAL     RANGE     DATE_ID     SITE     AREA     UNIT     Monthnumber     Year
    1111     35     36     50.45     2778     PLANT1     AREA2     CDU-4     8     2011
    1111     40     41     50.45     2783     PLANT1     AREA2     CDU-4     8     2011
    9010     114     37     50.45     2779     PLANT1     AREA2     CDU-3     8     2011
    9010     41     35     50.45     2784     PLANT1     AREA2     CDU-3     8     2011
    9011     1500     38     50.45     2789     PLANT2     AREA3     DHT-1     8     2011
    9012     43     37     50.45     2774     PLANT1     AREA1     DHT-2     8     2011
    9012     38     39     50.45     2781     PLANT1     AREA1     DHT-2     8     2011
    9013     39     40     50.45     2782     PLANT1     AREA2     FCC     8     2011How to ask question
    SQL and PL/SQL FAQ

  • Need SQL statement for this logic....

    Hi,
    I want a SQL statement for updating the following changed last number .
    Cuurently its:
    SELECT * FROM TEST;
    LAST NUMBER     CHANGED LAST NUMBER
    123518          
    12355265     
    123674659     
    9087648970     
    After updating with the required SQL statement table should look like
    LAST NUMBER     CHANGED LAST NUMBER
    123518          0000123518
    12355265     0012355265
    123674659     0123674659
    9087648970     9087648970
    the last number should be appended with ZEROs and the length of changed last number should be 10 always. Hope its clear.
    Appreciate your help.
    Thanks in advance
    Devender

    select last_number, lpad(to_char(last_number), 10 , '0') FROM test

  • I got an error in the RUNALLOCATION LOGIC VALIDATION

    Hi,
    I got an error in the RUNALLOCATION logic validation.
    The error message Dimension (NULL) was not found
    The logic:
    *RUNALLOCATION
    *FACTOR=0
    *APP WHAT=CorpBudget; WHERE=CorpBudget; USING=CorpBudget; TOTAL=CorpBudget
    *DIM Project WHAT=[SCTSQ1]="Y"; WHERE=<<<
    *DIM Entity WHAT=PC10105101; WHERE=PC10102106
    *DIM Account WHAT=880014; WHERE=58124
    *DIM DataSrc WHAT=INPUT; WHERE=<<<
    *DIM RptCurrency WHAT=LC; WHERE=<<<
    *DIM Client_Group WHAT=1010; WHERE=<<<
    *DIM Category WHAT=Budget; WHERE=<<<
    *DIM IntCo WHAT=Non_IntCo; WHERE=<<<
    *DIM Time WHAT=BAS(2011.TOTAL); WHERE=<<<
    *ENDALLOCATION
    *COMMIT
    Let me know where the error occurred in this logic validation and how can I solve this error.
    Thanks and Regards,
    Krishna.

    Hi Krishna,
    I am not clear what you are trying to achieve?
    But fore example if you wanted to allocate this year's budget based on last year's you could do below:
    *XDIM_MEMBERSET IntCo = Non_IntCo
    *XDIM_MEMBERSET Category = Budget
    *XDIM_MEMBERSET Client_Group = 1010
    *XDIM_MEMBERSET RptCurrency = LC
    *XDIM_MEMBERSET DataSrc = INPUT
    *RUNALLOCATION
    *FACTOR=USING/TOTAL
    *DIM Project           WHAT=SCTSQ1="Y";      WHERE=<<<;          USING=<<<;     TOTAL=<<<
    *DIM Entity           WHAT=PC10105101;      WHERE=PC10102106;     USING=<<<;     TOTAL=<<<           
    *DIM Account           WHAT=880014;           WHERE=58124;          USING=<<<;     TOTAL=<<<      
    *DIM Time           WHAT=BAS(2011.TOTAL);      WHERE=BAS(2011.TOTAL);     USING=BAS(2010.TOTAL);     TOTAL=<<<
    *ENDALLOCATION
    *COMMIT

  • Need pl/sql stmnts. for this simple logic

    Hi,
    I need PL/SQL program for this simple logic i am doing mistake somewhere unbale to trace
    out ..
    select * from GSR03_PO_DTL;
    PO_NUM
    L53177000 -- > no changes reqd (only one entry with new format)
    L00041677 --> to be updated to L41677000(only one entry with OLD format)
    L43677000 -- > no change reqd (exists one row with new format and old format like below)
    L00043677 -- > to be deleted this is old format (and new format like above already exists)
    EX:
    L00012345 --- old format
    L12345000 --- new format
    Hope question is clear. I written the following program.
    update is working fine but delete is not working.
    Please help.
    Thanks in Advance
    Devender
    declare
    Cursor c_test is
    (select po_num from GSR03_PO_DTL);
    BEGIN
    FOR r_test in c_Test
    LOOP
    dbms_output.put_line (r_test.po_num);
    IF ('L'||substr(r_test.po_num,5,5)) = ('L'||substr(r_test.po_num,2,5)) then
         dbms_output.put_line ('delete stmnt');
    END IF;     
    EXIT WHEN c_test%NOTFOUND;
    END LOOP;
    FOR r_test in c_Test
    LOOP
    IF r_test.po_num like 'L000%' then
    IF ('L'||substr(r_test.po_num,5,5)) is not NULL then
         update GSR03_PO_DTL set PO_NUM = 'L'||substr(po_num,5,5)||'000'
         where po_num like 'L000%' ;
         dbms_output.put_line ('update stmnt');
    END IF;     
    END IF;
    END LOOP;
    END;
    *********************

    No need for PL/SQL, man.
    SQL> SELECT po_no FROM po1
      2  /
    PO_NO
    L53177000
    L00041677
    L43677000
    L00043677
    SQL> UPDATE po1 y
      2  SET    y.po_no = 'L'||substr(y.po_no,5,5)||'000'
      3  WHERE  y.po_no LIKE 'L000%'
      4  AND    NOT EXISTS ( SELECT null FROM po1 x
      5                      WHERE x.po_no =  'L'||substr(y.po_no,5,5)||'000')
      6  /
    1 row updated.
    SQL> DELETE FROM po1 y
      2  WHERE  y.po_no LIKE 'L000%'
      3  AND    EXISTS ( SELECT null FROM po1 x
      4                  WHERE x.po_no =  'L'||substr(y.po_no,5,5)||'000')
      5  /
    1 row deleted.
    SQL> SELECT po_no FROM po1
      2  /
    PO_NO
    L53177000
    L41677000
    L43677000
    SQL> Cheers, APC

  • Oracle's SQL select should have a syntax like this

    Oracles SQL is very powerful but lacks a basic thing the LIMIT and OFFSET syntax which
    is present in postgres sql, I recommend oracle to support this syntax in future release.
    more details of this syntax can be found at :
    http://www.postgresql.org/idocs/index.php?sql-select.html
    SELECT [ ALL | DISTINCT [ ON ( expression [, ...] ) ] ]
    * | expression [ AS output_name ] [, ...]
    [ FROM from_item [, ...] ]
    [ WHERE condition ]
    [ GROUP BY expression [, ...] ]
    [ HAVING condition [, ...] ]
    [ { UNION | INTERSECT | EXCEPT } [ ALL ] select ]
    [ ORDER BY expression [ ASC | DESC | USING operator ] [, ...] ]
    [ FOR UPDATE [ OF tablename [, ...] ] ]
    [ LIMIT { count | ALL } ]
    [ OFFSET start ]

    I've executed the above queries against my table and the results follows :
    The structure of the table
    Name Null? Type
    FATWAID NOT NULL NUMBER(11)
    FATWASTATUS NUMBER(1)
    SUBJ_NO NUMBER(4)
    LANG CHAR(1)
    SCHOLAR NUMBER(2)
    REVIEWER NUMBER(2)
    AUDITOR NUMBER(2)
    PUBLISHER NUMBER(2)
    SUBSCRIBER NUMBER(2)
    ENTRY NUMBER(2)
    FATWATITLE VARCHAR2(100)
    FATWATEXT CLOB
    FATWADATE DATE
    TRANSLATE CHAR(1)
    SELECTED NUMBER(1)
    SUBJ_MAIN NUMBER(4)
    I have set timing on and executed each query above, following are the statistics.
    First the number of rows in the table.
    SQL>set timing on
    SQL>select count (*) from fatwa;
    COUNT(*)
    1179651
    Elapsed: 00:00:13.05
    The query of Andrew Clarke
    SQL>SELECT fatwaid FROM (SELECT fatwaid, rownum as ranking FROM fatwa) r
    WHERE r.ranking BETWEEN &OFFSET AND &LIMIT
    SQL>/
    Enter value for offset: 100000
    Enter value for limit: 100009
    old 2: WHERE r.ranking BETWEEN &OFFSET AND &LIMIT
    new 2: WHERE r.ranking BETWEEN 100000 AND 100009
    FATWAID
    96592
    96593
    96594
    96595
    96596
    96597
    96598
    96599
    96600
    96601
    10 rows selected.
    Elapsed: 00:00:12.02
    SQL> /
    Enter value for offset: 1000000
    Enter value for limit: 1000009
    old 2: WHERE r.ranking BETWEEN &OFFSET AND &LIMIT
    new 2: WHERE r.ranking BETWEEN 1000000 AND 1000009
    FATWAID
    994621
    994622
    994623
    994624
    994625
    994626
    995769
    995770
    995771
    995772
    10 rows selected.
    Elapsed: 00:00:12.00
    The response time is decreasing because of use of bind variables,
    but 12 seconds is a sign of poor performance.
    Now a slight modification to Clarke's query
    I will add order by clause
    SQL> ed
    Wrote file afiedt.buf
    1 SELECT fatwaid FROM (SELECT fatwaid, rownum as ranking FROM fatwa ORDER BY fatwaid) r
    2* WHERE r.ranking BETWEEN &OFFSET AND &LIMIT
    SQL> /
    Enter value for offset: 100001
    Enter value for limit: 100010
    old 2: WHERE r.ranking BETWEEN &OFFSET AND &LIMIT
    new 2: WHERE r.ranking BETWEEN 100001 AND 100010
    FATWAID
    100032
    100033
    100034
    100035
    100036
    100037
    100038
    100039
    100040
    100041
    10 rows selected.
    Elapsed: 00:00:04.00 -- time reduced from 12 to 4 seconds
    A time of 4 seconds is acceptable but not good,
    response time should be in milli seconds.
    SQL> /
    Enter value for offset: 1000001
    Enter value for limit: 1000010
    old 2: WHERE r.ranking BETWEEN &OFFSET AND &LIMIT
    new 2: WHERE r.ranking BETWEEN 1000001 AND 1000010
    FATWAID
    1000032
    1000033
    1000034
    1000035
    1000036
    1000037
    1000038
    1000039
    1000040
    1000041
    10 rows selected.
    Elapsed: 00:00:03.09 -- this reduction is because of bind variables
    The query of Chris Gates
    SQL>select fatwaid
    2 from ( select a.*, rownum r
    3 from ( select *
    4 from fatwa
    5 --where x = :host_variable
    6 order by fatwaid ) a
    7 where rownum < &HigerBound )
    8 where r > &LowerBound
    SQL> /
    Enter value for higerbound: 100011
    old 7: where rownum < &HigerBound )
    new 7: where rownum < 100011 )
    Enter value for lowerbound: 100000
    old 8: where r > &LowerBound
    new 8: where r > 100000
    FATWAID
    100032
    100033
    100034
    100035
    100036
    100037
    100038
    100039
    100040
    100041
    10 rows selected.
    Elapsed: 00:00:02.04
    This seems to be fast
    SQL> /
    Enter value for higerbound: 1000011
    old 7: where rownum < &HigerBound )
    new 7: where rownum < 1000011 )
    Enter value for lowerbound: 1000000
    old 8: where r > &LowerBound
    new 8: where r > 1000000
    FATWAID
    1000032
    1000033
    1000034
    1000035
    1000036
    1000037
    1000038
    1000039
    1000040
    1000041
    10 rows selected.
    Elapsed: 00:01:14.02
    but this is worst when upper bound is 1 million.
    Finally Myers query
    SQL> select fatwaid from
    2 (select /*+ INDEX(fawtaid pk_fatwa) */ fatwaid, rownum x from fatwa
    3 where rownum < &UpperBound )
    4 where x > &LowerBound;
    Enter value for upperbound: 100011
    old 3: where rownum < &UpperBound )
    new 3: where rownum < 100011 )
    Enter value for lowerbound: 100000
    old 4: where x > &LowerBound
    new 4: where x > 100000
    FATWAID
    122418
    122419
    122420
    122421
    122422
    122423
    122424
    122425
    122426
    122427
    10 rows selected.
    Elapsed: 00:00:00.03 -- too fast
    SQL> /
    Enter value for upperbound: 1000011
    old 3: where rownum < &UpperBound )
    new 3: where rownum < 1000011 )
    Enter value for lowerbound: 1000000
    old 4: where x > &LowerBound
    new 4: where x > 1000000
    FATWAID
    984211
    984212
    984213
    984214
    984215
    984216
    984217
    984218
    984219
    984220
    10 rows selected.
    Elapsed: 00:00:02.02 -- with 1 million rows also satisfactory but it is not is milliseconds
    The same query after using order by clause
    SQL> select fatwaid from
    2 (select /*+ INDEX(fawtaid pk_fatwa) */ fatwaid, rownum x from fatwa
    3 where rownum < &UpperBound ORDER BY fatwaid)
    4 where x > &LowerBound;
    Enter value for upperbound: 100011
    old 3: where rownum < &UpperBound ORDER BY fatwaid)
    new 3: where rownum < 100011 ORDER BY fatwaid)
    Enter value for lowerbound: 100000
    old 4: where x > &LowerBound
    new 4: where x > 100000
    FATWAID
    100032
    100033
    100034
    100035
    100036
    100037
    100038
    100039
    100040
    100041
    10 rows selected.
    Elapsed: 00:00:00.06
    SQL> /
    Enter value for upperbound: 1000011
    old 3: where rownum < &UpperBound ORDER BY fatwaid)
    new 3: where rownum < 1000011 ORDER BY fatwaid)
    Enter value for lowerbound: 1000000
    old 4: where x > &LowerBound
    new 4: where x > 1000000
    FATWAID
    1000032
    1000033
    1000034
    1000035
    1000036
    1000037
    1000038
    1000039
    1000040
    1000041
    10 rows selected.
    Elapsed: 00:00:07.03 -- slow
    SQL> /
    Enter value for upperbound: 1000011
    old 3: where rownum < &UpperBound ORDER BY fatwaid)
    new 3: where rownum < 1000011 ORDER BY fatwaid)
    Enter value for lowerbound: 1000000
    old 4: where x > &LowerBound
    new 4: where x > 1000000
    FATWAID
    1000032
    1000033
    1000034
    1000035
    1000036
    1000037
    1000038
    1000039
    1000040
    1000041
    10 rows selected.
    Elapsed: 00:00:00.06
    when I execute the same query again it is bringing records from
    the SGA so it is very fast
    Now which one to choose from ?
    Andrew and Myers queries are good and currently I am using
    Myers query.
    There should be some technique to do this in the most efficient way.
    any input is appreciated.

  • Write an sql select statement for this problem?????????????????

    Hi frenz, i m bharath a new bee to oracle,my problem is
    the given table is
    userid billno amount
    1 101 1000
    2 102 2000
    3 103 3000
    4 104 4000
    output table should be:
    userid billno amount total*
    1 101 1000
    2 102 2000 *3000*
    3 103 3000 *6000*
    4 104 4000 *10000*
    I need a select query for the above output.
    i.e,here i calculated total as sum(amount) for each row,i.e,3000 = 1000+2000,6000 = 1000+2000+3000,10000 = 1000+2000+3000+4000 by this way my calculation for total field
    kindly send me a query.

    This is trivial with analytics:
    SQL> select empno, sal, sum(sal) over (order by empno)
      2  from emp
      3  /
         EMPNO        SAL SUM(SAL)OVER(ORDERBYEMPNO)
          7369        800                        800
          7499       1600                       2400
          7521       1250                       3650
          7566       2975                       6625
          7654       1250                       7875
          7698       2850                      10725
          7782       2450                      13175
          7788       3000                      16175
          7839       5000                      21175
          7844       1500                      22675
          7876       1100                      23775
          7900        950                      24725
          7902       3000                      27725
          7934       1300                      29025
    14 rows selected.
    SQL> You might want to get your keyboard checked - the question mark key seems to be stuck.
    Cheers, APC
    blog: http://radiofreetooting.blogspot.com

  • Booleans API Functions into SQL SELECT

    Hello,
    our API is using a huge set of boolean «is_{what we want to check}» functions. These simple atomic functions are used into more sophisticated PL/SQL funcs or procs.
    Sometime, we need to use these bool funcs directly into our SQL queries.
    Here is a simplified example we want:
    SELECT id1, id2, is_valid(id1, id2)
    FROM table
    WHERE ... stuff ...;
    or
    SELECT col1, col2, ...
    FROM table
    WHERE is_valid(id1, id2) IS TRUE ;
    or
    SELECT col1, col2, ...
    FROM table
    WHERE is_valid(id1, id2) = TRUE ;
    to be valid queries....
    I know that booleans aren't supported natively in the SQL, I created a function that translate bool to char:
    FUNCTION bool_to_char (p_bool IN BOOLEAN)
    RETURN VARCHAR2
    IS
    v_retour VARCHAR2 (5);
    BEGIN
    v_retour := CASE p_bool
    WHEN TRUE
    THEN 'TRUE'
    WHEN FALSE
    THEN 'FALSE'
    END;
    RETURN v_retour;
    END;
    So, when I call this func into my sql, it's not working anymore:
    SELECT id1, id2, bool_to_char(is_valid(id1, id2))
    FROM table
    WHERE ... stuff ...;
    or
    SELECT col1, col2, ...
    FROM table
    WHERE bool_to_char(is_valid(id1, id2)) = 'TRUE';
    I'm searching for a solution to make this possible... The only fast solution that came in my mind is to encapsulate every boolean functions to return a corresponding varchar value. Not that good....
    Any ideas or suggestions?

    SQL standards have been developed over the years and whilst some vendors have tweaked SQL functionality to make their database better than others, one thing that is not part of SQL standards is support for BOOLEAN. 3GL and 4GL languages most often support boolean values, which are represented internally as a binary number.
    For those interested, in some languages the BOOLEAN is represented as -1 for TRUE and 0 for FALSE. In binary, -1 is represented as all the bits set to 1 whilst 0 is all the bits set to 0. There was a nice feature in one of the BASIC versions (I think it was BBC Basic if I remember correctly) that allowed you to use booleans within assignments such as...
    x := y + (z AND (y < 100))If the "y<100" condition evaluated to TRUE, this would translate as...
    x := y + (z AND TRUE)which, in binary terms (let's assume all numbers are single bytes for illustrative purposes) would be...
    x := y + (z AND 11111111)The "z AND 11111111" would perform a logical AND between the z value and the binary 11111111 resulting in a value of z... giving...
    x := y + zIf the condition evaluated to false on the other hand it would go as follows...
    x := y + (z AND FALSE)
    x := y + (z AND 00000000)So, "z AND 00000000" would logically AND to give a result of 0 and thus giving...
    x := ySo it was useful to use in conditional arithmetic, avoiding having to put IF statements in the code.
    Getting back to the thread...
    Using PL/SQL functions so extensively in SQL is a bad idea as it will inevitably cause a lot of context switching between the SQL and PL/SQL engines. This will have a noticable effect on performance of queries. Where possible, if the test can be done within SQL, then it should be done there rather than calling PL/SQL.
    ;)

  • How to write code for this logic, plz help me very urgent

    Hi All,
    i am new to sap-abap, i got this work and i m working on this can any body help me in writing code, plz help me, this is very very urgent.
    here  i m giving my logic, can anybody send me the code related to this logic.
    this is very urgent .
    this program o/p should be in ALV format and need to create one commond 'SAVE" on this o/t list  if  user clicks save processedon and processedby fields in ZFIBUE should be updated automatically.
    i am creating one custom table zfibue having fields: (serialno, bukrs, matnr,prdha,hkont,gsber,wrbtr,budat, credate, cretime,processed, processedon, processedby,mapped)
    fields of zfibue:
    serailno = numc
    bukrs = char
    matnr = char
    prdha = char
    hkont = char
    gsber = char
    wrbtr = char
    budat = date
    credate = date
    cretime = time
    processed= char
    processedon = date
    processedby = char
    mapped = char      are   belongs to above type data types
    and seelct-optionfields:  s_bukrs for bseg-bukrs
                                        s_hkont for bseg-hkont,
                                         s_budat for bkpf-budat,
                                         s_processed for zfibue-processed,
                                          s_processedon for zfibue-processedon,
                                          s_mapped. for zfibue-mapped
    parameters: p_chk1 as checkbox,
                      p_chk2 as checkbox.
                      p_filepath type rlgrap-filename.
    1.1 Validate the user inputs (S_BUKRS and S_HKONT) against respective check tables (T001 and SKB1). If the validation fails, provide respective error message. Eg: “Invalid input for Company Code”.
    1.2 Fetch SERIALNO, BUKRS, MATNR, PRDHA, HKONT, GSBER, WRBTR, BUDAT, CREDATE, CRETIME, PROCESSED, PROCESSEDON, PROCESSEDBY, MAPPED from table ZFIBUE into internal table GT_ZFIBUE where BUKRS IN S_BUKRS, HKONT IN S_HKONT, BUDAT IN S_BUDAT, PROCESSED IN S_PROCESSED, PROCESSEDON IN S_PROCESSEDON, and MAPPED IN S_MAPPED.
    1.3 If P_CHK2 = ‘X’, go to step 1.11. Else continue.
    1.4 If P_CHK1 = ‘X’, continue. Else go to step 1.9
    1.5 Fetch MATNR, PRDHA from MARA into GT_MARA for all entries in GT_ZFIBUE where MATNR = GT_ZFIBUE-MATNR.
    1.6 Sort and delete adjacent duplicates from GT_MARA based on MATNR.
    1.7 Loop through GT_ZFIBUE where PRDHA = blank.
              Read Table GT_MARA based on MATNR = GT_ZFIBUE-MATNR.
              IF sy-subrc = 0.
                     Move GT_MARA-PRDHA to GT_ZFIBUE-PRDHA.
                  Modify Table GT_ZFIBUE. “Update Product Hierarchy
                 Endif.
        Fetch PRDHA, GSBER from ZFIBU into GT_ZFIBU for all entries in GT_ZFIBUE where PRDHA = GT_ZFIBUE-PRDHA.
        Read Table GT_ZFIBU based on PRDHA = GT_ZFIBUE-PRDHA.
              IF sy-subrc = 0.
                     Move GT_ZFIBU-GSBER to GT_ZFIBUE-GSBER.
                  Move “X” to GT_ZFIBUE-MAPPED.      
                  Modify Table GT_ZFIBUE.
                 Endif.   
    Endloop.
    1.8 Modify database table ZFIBUE from GT_ZFIBUE.
    1.9 Fill the field catalog table GT_FIELDCAT using the details of output fields listed in section “Inputs/Outputs” (above).
       Eg:                 LWA_ FIELDCAT -SELTEXT_L = 'Serial Number’.
                              LWA_ FIELDCAT -DATATYPE = ‘NUMC’.
                              LWA_ FIELDCAT -OUTPUTLEN = 9.
                              LWA_ FIELDCAT -TABNAME = 'GT_ZFIBUE'.
                              LWA_ FIELDCAT-FIELDNAME = 'SERIALNO'.
              Append LWA_FIELDCAT to GT_FIELDCAT
    Note: a) The output field GT_ZFIBUE-PROCESSED will be editable marking INPUT = “X” in field catalog (GT_FIELDCAT).
             b) The standard ALV functionality will be used to give the user option for selecting all or blocks of entries at a time.
             c) The PF-STATUS STANDARD_FULLSCREEN from function group SLVC_FULLSCREEN will be copied to the program and modified to include a “SAVE” button.
    1.10 Call the function module REUSE_ALV_GRID_DISPLAY passing output table GT_ZFIBUE and field catalog GT_FIELDCAT. Additional parameters like I_CALLBACK_PF_STATUS_SET (= ‘ZFIBUESTAT’) and I_CALLBACK_USER_COMMAND (=’HANDLE_USER_ACTION’) will also be passed to handle user events. Go to 2.14.
    1.11 Download the file to P_FILEPATH using function module GUI_DOWNLOAD passing GT_ZFIBUE.
    1.12 Exit Program.
    Logic to be implemented in  routine “Handle_User_Action”
    This routine will have the following interface:
    FORM Handle_User_Action  USING r_ucomm LIKE sy-ucomm
                                                               rs_selfield TYPE slis_selfield.
    ENDFORM.
    Following logic will be implemented in this routine:
    1.     If r_ucomm = ‘SAVE’, continue. Else exit.
    2.     Loop through GT_ZFIBUE where SEL_ROW = ‘X’. “Row is selected
    a.     IF GT_ZFIBUE-PROCESSED = ‘X’.
    i.     GT_ZFIBUE-PROCESSEDON = SY-DATUM.
    ii.     GT_ZFIBUE-PROCESSEDBY = SY-UNAME.
    iii.     MODIFY ZFIBUE FROM work area GT_ZFIBUE.
    Endif.
    Endloop.

    Hi Swathi,
    If it's very very urgent then you better get on with it, don't waste time on the web. Chop chop.

  • Sql select query problem

    hi friends,
    i've a view called "risk_efforts" with fields user_id,user_name,wknd_dt,week_day,prod_efforts,unprod_efforts.
    Name Type
    ROW_ID NUMBER
    USER_ID VARCHAR2(14)
    USER_NAME VARCHAR2(50)
    WKND_DT VARCHAR2(8)
    WEEK_DAY VARCHAR2(250)
    PROD_EFFORTS NUMBER
    UNPROD_EFFORTS NUMBER
    data is like this:
    when there is some data in prod_efforts, unprod_efforts will be null
    when there is some data in unprod_efforts, prod_efforts will be null
    for example:
    USER_ID     USER_NAME     WKND_DT     WEEK_DAY     PROD_EFFORTS     UNPROD_EFFORTS
    G666999     GTest     20100403     TUE     null 3
    G666999     GTest     20100403     TUE     14     null
    now i want to combine these 2 rows into 1 row i.e o/p should be like this
    USER_ID     USER_NAME     WKND_DT     WEEK_DAY     PROD_EFFORTS     UNPROD_EFFORTS
    G666999     GTest     20100403     TUE     14 3
    i've tried all combinations but couldn't get the query. Please help me with the exact SQL select query.
    thanks,
    Girish

    Welcome to the forum.
    First read this:
    Urgency in online postings
    Secondly, it's always helpful to provide the following:
    1. Oracle version (SELECT * FROM V$VERSION)
    2. Sample data in the form of CREATE / INSERT statements.
    3. Expected output
    4. Explanation of expected output (A.K.A. "business logic")
    5. Use \ tags for #2 and #3. See FAQ (Link on top right side) for details.
    You have provided #3 and #4. However with no usable form of sample data forum members will often not respond as quickly as they could if you provided #2.
    I'm just wagering a guess here but what about this:SELECT ROW_ID
    , USER_ID
    , WKND_DT
    , WEEK_DAY
    , MAX(PROD_EFFORTS) AS PROD_EFFORTS
    , MAX(UNPROD_EFFORTS) AS UNPROD_EFFORTS
    FROM RISK_EFFORTS
    GROUP BY ROW_ID
    , USER_ID
    , WKND_DT
    , WEEK_DAY                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Need help for SQL SELECT query to fetch XML records from Oracle tables having CLOB field

    Hello,
    I have a scenario wherein i need to fetch records from several oracle tables having CLOB fields(which is holding XML) and then merge them logically to form a hierarchy XML. All these tables are related with PK-FK relationship. This XML hierarchy is having 'OP' as top-most root node and ‘DE’ as it’s bottom-most node with One-To-Many relationship. Hence, Each OP can have multiple GM, Each GM can have multiple DM and so on.
    Table structures are mentioned below:
    OP:
    Name                             Null                    Type        
    OP_NBR                    NOT NULL      NUMBER(4)    (Primary Key)
    OP_DESC                                        VARCHAR2(50)
    OP_PAYLOD_XML                           CLOB       
    GM:
    Name                          Null                   Type        
    GM_NBR                  NOT NULL       NUMBER(4)    (Primary Key)
    GM_DESC                                       VARCHAR2(40)
    OP_NBR               NOT NULL          NUMBER(4)    (Foreign Key)
    GM_PAYLOD_XML                          CLOB   
    DM:
    Name                          Null                    Type        
    DM_NBR                  NOT NULL         NUMBER(4)    (Primary Key)
    DM_DESC                                         VARCHAR2(40)
    GM_NBR                  NOT NULL         NUMBER(4)    (Foreign Key)
    DM_PAYLOD_XML                            CLOB       
    DE:
    Name                          Null                    Type        
    DE_NBR                     NOT NULL           NUMBER(4)    (Primary Key)
    DE_DESC                   NOT NULL           VARCHAR2(40)
    DM_NBR                    NOT NULL           NUMBER(4)    (Foreign Key)
    DE_PAYLOD_XML                                CLOB    
    +++++++++++++++++++++++++++++++++++++++++++++++++++++
    SELECT
    j.op_nbr||'||'||j.op_desc||'||'||j.op_paylod_xml AS op_paylod_xml,
    i.gm_nbr||'||'||i.gm_desc||'||'||i.gm_paylod_xml AS gm_paylod_xml,
    h.dm_nbr||'||'||h.dm_desc||'||'||h.dm_paylod_xml AS dm_paylod_xml,
    g.de_nbr||'||'||g.de_desc||'||'||g.de_paylod_xml AS de_paylod_xml,
    FROM
    DE g, DM h, GM i, OP j
    WHERE
    h.dm_nbr = g.dm_nbr(+) and
    i.gm_nbr = h.gm_nbr(+) and
    j.op_nbr = i.op_nbr(+)
    +++++++++++++++++++++++++++++++++++++++++++++++++++++
    I am using above SQL select statement for fetching the XML records and this gives me all related xmls for each entity in a single record(OP, GM, DM. DE). Output of this SQL query is as below:
    Current O/P:
    <resultSet>
         <Record1>
              <OP_PAYLOD_XML1>
              <GM_PAYLOD_XML1>
              <DM_PAYLOD_XML1>
              <DE_PAYLOD_XML1>
         </Record1>
         <Record2>
              <OP_PAYLOD_XML2>
              <GM_PAYLOD_XML2>
              <DM_PAYLOD_XML2>
              <DE_PAYLOD_XML2>
         </Record2>
         <RecordN>
              <OP_PAYLOD_XMLN>
              <GM_PAYLOD_XMLN>
              <DM_PAYLOD_XMLN>
              <DE_PAYLOD_XMLN>
         </RecordN>
    </resultSet>
    Now i want to change my SQL query so that i get following output structure:
    <resultSet>
         <Record>
              <OP_PAYLOD_XML1>
              <GM_PAYLOD_XML1>
              <GM_PAYLOD_XML2> .......
              <GM_PAYLOD_XMLN>
              <DM_PAYLOD_XML1>
              <DM_PAYLOD_XML2> .......
              <DM_PAYLOD_XMLN>
              <DE_PAYLOD_XML1>
              <DE_PAYLOD_XML2> .......
              <DE_PAYLOD_XMLN>
         </Record>
         <Record>
              <OP_PAYLOD_XML2>
              <GM_PAYLOD_XML1'>
              <GM_PAYLOD_XML2'> .......
              <GM_PAYLOD_XMLN'>
              <DM_PAYLOD_XML1'>
              <DM_PAYLOD_XML2'> .......
              <DM_PAYLOD_XMLN'>
              <DE_PAYLOD_XML1'>
              <DE_PAYLOD_XML2'> .......
              <DE_PAYLOD_XMLN'>
         </Record>
    <resultSet>
    Appreciate your help in this regard!

    Hi,
    A few questions :
    How's your first query supposed to give you an XML output like you show ?
    Is there something you're not telling us?
    What's the content of, for example, <OP_PAYLOD_XML1> ?
    I don't think it's a good idea to embed the node level in the tag name, it would make much sense to expose that as an attribute.
    What's the db version BTW?

  • [Forum FAQ] Troubleshooting error "The specified SQL server instance is not valid" when installing SCOM reporting service

    Symptom
    If you have failed to install SCOM reporting service, you may encounter below error when you reinstall it:
    “The specified SQL server instance is not valid”.
    (Figure 1)
    Figure 1.
    Reason
    This issue may be caused by multiple reasons, for example the reasons in Figure 1.
    However, you may find that SSRS and Report Server website are configured correctly and no SSL or proxy Server is used. In these scenario, you can open the log file under path
    to find the root reason:
    C:\Program Files\Microsoft SQL Server\MSRS11.MSSQLSERVER\Reporting Services\LogFiles
    Later, you will find the error as below:
    ERROR: Throwing Microsoft.ReportingServices.Library.ReportServerDisabledException: , Microsoft.ReportingServices.Library.ReportServerDisabledException:
    The report server cannot decrypt the symmetric key that is used to access sensitive or encrypted data in a report server database. You must either restore a backup key or delete all encrypted content. ---> System.Runtime.InteropServices.COMException
    (0x80090016): Keyset does not exist (Exception from HRESULT: 0x80090016)
    at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
    at RSManagedCrypto.RSCrypto.ReencryptSymmetricKey(Byte[] symKeyBlob, Byte[] pPublicKeyBlob)
    at Microsoft.ReportingServices.Library.ConnectionManager.<GetEncryptionKey>b__2()
    --- End of inner exception stack trace ---;
    Solution
    According to the error message, you can delete encrypted content by following the steps below:
    Open SQL Reporting Services Configuration Manager.
    Select “Encryption Keys”.
    Click “Delete” to delete all encrypted content. (Figure 2)
    Figure 2.
    After that, we can install SCOM reporting service again, after successfully install reporting service, we should see the SCOM operation console as below:
    Figure 3.
    In addition, you may also encounter other errors when installing SCOM reporting service, and the troubleshooting steps may be different. However, we can also check SQL reporting
    service logs to find the root reason.
    Here are some articles that would be helpful for SCOM reporting service installation and troubleshooting:
    How to Install the Operations Manager Reporting Server
    http://technet.microsoft.com/en-us/library/hh298611.aspx
    Unable to install SCOM 2012 Reporting Services
    http://blogs.technet.com/b/mdegre/archive/2013/05/27/unable-to-install-scom-2012-reporting-services.aspx
    Please click to vote if the post helps you. This can be beneficial to other community members reading the thread.

    Hello,
    I'm afraid you must use a dedicated instance of SQL Server for each site(SCOM/SCCM). Some similar issues were disscussed on this forum:
    SCCM and SCOM - SQL Server 
    http://social.technet.microsoft.com/Forums/en-US/configmanagergeneral/thread/bfa14da9-4692-4c64-a107-e085c967d259
    SCOM, SCCM, SQL on same server?
    http://social.technet.microsoft.com/Forums/en-US/configmgrsetup/thread/b5373aa7-5233-4b1f-9b39-b86e481e04d5
    Thanks,
    Yog Li
    TechNet Community Support

  • SQL LOADER  message : Point de validation COMMIT atteint - nombre d'enreg

    Hello
    I am loading a csv file into an oracle table via SQL LOADER
    Each time i invoke it i get the folowing message :
    SQL LOADER message : Point de validation <COMMIT> atteint - nombre d'enregis. logiques 52. (i am french version of apex)
    And the table is left empty.
    The translation of the above message is :
    SQL LOADER Validation Point <COMMIT> reached. number of logical records 52
    What doese it mean ?
    Thanks in advance.

    Yes
    my table is empty and
    and this is my control file :
    load data
    infile 'i:\csvs\mvh051.csv'
    into table mvhist051
    fields terminated by ';' optionally enclosed by '"'
    (ETABLI,NUPIECE,NUMLIGNE,DATEOP,JOURNAL,COMPTE,CODEN,LIBELLE,MONTANT,SENS,DATEVALEUR,OPERATION,NPIECE,CORIG,SOLDE,MVAPUR)
    hear is a sample of bide file :
    5100;2052;1;01/01/2005;ARB;1120060;0;report de solde 2004;6122867,27;D;01/01/2005;98;;1
    5100;2053;1;01/01/2005;ARB;1120070;0;report de solde 2004;223639,17;D;01/01/2005;98;;1
    5100;2054;1;01/01/2005;ARB;1261000;0;report de solde 2004;4680204207,00;D;01/01/2005;98;;1
    5100;2055;1;01/01/2005;ARB;1271100;0;report de solde 2004;81895715591,44;D;01/01/2005;98;;1
    ETABLI;NUPIECE;NUMLIGNE;DATEOP;JOURNAL;COMPTE;CODEN;LIBELLE;MONTANT;SENS;DATEVALEUR;OPERATION;NPIECE;CORIG;SOLDE;MVAPUR
    Please not that the last line is the heading columns names. I dont under stand why
    it is copied.

  • Please provide code for this logic

    Hi,
    table
    id                    code
    145623          xyz001
    178956          sbh002
    165895          sbi003
    As per this logic,for  every new entity of id a new autogenerated code will be  generated.
    This (xyz or sbh or sbi) code should be fetched using select query (select b_code into table.code from cmp where c_id =145623)
    using id(145623). And 001,002 is autogenerated code and should be concentrated with xyz ex: xyz001
    Here we can use trigger with sequence
    Could you please help me..

    How many times you will ask same question???
    You need to use pl/sql block for your requirement   some thing like this:
    create sequence and add into pl/sql block like:
    >>Select max(count) into temp_var where id=’sbi’
    >>New_code:=’sbi’+temp_var;
    Now you need to optimize it...
    Thanks...

Maybe you are looking for

  • Set For Wireless Operation

    Trying to set up the wireless function but cannot find original software disc and the procedure asks that I insert the disc.

  • Can I get a unlocked iPhone 5 in the store

    Can I get a unlocked iPhone 5 in the store in USA

  • PXI Chassis Power LED Flashing Red: What to do?

    My NI PXI-1042 keeps blinking red the Power LED. I know it means the voltage is out of the specs. What to do?

  • Deactivate when CS3 won't open?

    We have CS3 with a student license.  After 4-5 years when we try to start PS we get an error message that says "license stopped working."  It goes on to suggest uninstalling and reinstalling.  An Adobe readme says to deactivate before uninstalling. 

  • Heirarchy Tree in a Master Detail Relationship

    I am trying to use the heirarchy tree in a multiple tab interface form in Forms 6i. I have the tree populating properly on the initial master record query. However, I can't get the tree to clear on subsequent queries, like a master-detail clears on a