Help need in selection query

Hi ,
I have a field(test) in ztable(zxxx) whose length is 12 char and while updating it
only 10 digits were updated and there are no zeros in front of the value in order to make it
12 digit.
Now i need this parameter to be included in another program selection screen.
Now i have given it as
parameter :  test(12) type n.
it works fine when it has an entry , when it is blank i has to retrieve all records but in this case
i won't because it has a value of 000000000000
noe when i declare like this
paramter : test like zxxx-test.
when my input is 123456, it won't fetch me any value because it has to be 0000123456 because it has been updated like in the table.
There was a purpose in updating this way.
Now my code is like this
parameters : test(10) type n.
select-options :   kostl for zxxx-kostl NO-EXTENSION NO INTERVALS,
      p_uname for zxxx-uname NO-EXTENSION NO INTERVALS.
if test is initial.
select * from zxxx into table itab where kostl in kostl and uname in p_uname.
else.
select * from zxxx into table itab where aufnr  = order and
                               kostl in kostl and uname in p_uname.
endif
PLEASE SUGGEST ME IF THERE IS AN ALTERNATE BETTER WAY.
or this is the best way
Thanks

Hi
as per my knowledge what you have done is right.
Thanks
KAJOL

Similar Messages

  • Help needed in select query

    Hi,
    I need to select the max time for the transaction using the below query. I’m able to get the o/p. Here the problem is I need to fetch the corrletorid (primary key) as well. if try to get that I’m getting the o/p like case2.
    I want the o/p to be like case 1 with the corrleator id . plz help me to get the o/p.
    Case 1: select b.TransactionName, max(to_char(b.duration, 'mm/dd/yyyy hh24:mi:ss.ff')) as average from trandetails a,subtrandetails b where a.CORRELATORID=b.PCORRELATORID and b.PCORRELATORID='11' group by b.transactionname
    TRANSACTIONNAME MAXTIME
    FINT3 12/10/2007 19:53:09.042000
    FINT 12/10/2007 19:31:07.042000
    FINT2 12/10/2007 19:31:07.042000
    SQL> /
    Case 2: select b.TransactionName,b.correlatorid, max(to_char(b.duration, 'mm/dd/yyyy hh24:mi:ss.ff')) as average from trandetails a,subtrandetails b where a.CORRELATORID=b.PCORRELATORID and b.PCORRELATORID='11' group by b.transactionname,b.correlatorid
    SQL> /
    TRANSACTIONNAME CORRELATORID AVERAGE
    FINT2 102 12/10/2007 19:31:07.042000
    FINT3 108 12/10/2007 19:53:09.042000
    FINT3 103 12/10/2007 19:31:07.042000
    FINT 101 12/10/2007 19:31:07.042000
    in the above output i should have only record(max time) for FINT3.
    Thank

    Sharma,
    Please find the below sample data(insert stmt and create table):
    ======================================
    create table trandetails(
    correlatorid varchar2(20) CONSTRAINT correlatorid_FKey REFERENCES Subtrandetails(correlatorid),
    username varchar2(25) NOT NULL,
    applicationname varchar2(25) NOT NULL,CONSTRAINT composite1_pkey1 PRIMARY KEY(correlatorid ,applicationname));
    create table Subtrandetails(
    correlatorid varchar2(20) PRIMARY KEY,
    PCORRELATORID      varchar2(20),
    TransactionName varchar2(25) NOT NULL,
    Machinename varchar2(15) NOT NULL,
    STARTDATE timestamp NOT NULL,
    ENDDATE timestamp NOT NULL,
    SourceName varchar2(25),
    FunctionName varchar2(25),
    LOC number(5),
    CONTEXTPROPERTY1 varchar2(25),
    CONTEXTPROPERTY2 varchar2(25),
    CONTEXTPROPERTY3 varchar2(25),
    TransactionStatus varchar2(25) NOT NULL CONSTRAINT Transaction1_Status_chk Check (TransactionStatus in ('Success', 'Failure', 'Abort')));
    INSERT INTO trandetails VALUES ('11','FINAPP','ANUAPP1');
    INSERT INTO trandetails VALUES ('13','FINTEST','ANUAPP2');
    INSERT INTO
    Subtrandetails(correlatorid,PCORRELATORID ,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
    VALUES ('10','1','ARM','blrkec95931d','10-DEC-07 03.24.07.042000 PM','10-DEC-07 03.31.07.042000 PM','Success');
    INSERT INTO
    Subtrandetails(correlatorid,PCORRELATORID ,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
    VALUES ('11','1','ARM1','blrkec95931d','10-DEC-07 04.24.07.042000 PM','10-DEC-07 04.31.07.042000 PM','Success');
    INSERT INTO
    Subtrandetails(correlatorid,PCORRELATORID ,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
    VALUES ('12','1','ARM2','blrkec95931d','10-DEC-07 05.24.07.042000 PM','10-DEC-07 05.31.07.042000 PM','Success');
    INSERT INTO
    Subtrandetails(correlatorid,PCORRELATORID ,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
    VALUES ('13','1','ARM3','blrkec95931d','10-DEC-07 06.24.07.042000 PM','10-DEC-07 06.31.07.042000 PM','Success');
    INSERT INTO
    Subtrandetails(correlatorid,PCORRELATORID ,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
    VALUES ('14','1','ARM4','blrkec95931d','10-DEC-07 07.24.07.042000 PM','10-DEC-07 07.31.07.042000 PM','Success');
    INSERT INTO
    Subtrandetails(correlatorid,PCORRELATORID ,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
    VALUES ('101','11','FINT','blrkec95931d','10-DEC-07 07.24.07.042000 PM','10-DEC-07 07.31.07.042000 PM','Success');
    INSERT INTO
    Subtrandetails(correlatorid,PCORRELATORID ,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
    VALUES ('102','11','FINT2','blrkec95931d','10-DEC-07 07.24.07.042000 PM','10-DEC-07 07.31.07.042000 PM','Success');
    INSERT INTO
    Subtrandetails(correlatorid,PCORRELATORID ,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
    VALUES ('103','11','FINT3','blrkec95931d','10-DEC-07 07.24.07.042000 PM','10-DEC-07 07.31.07.042000 PM','Success');
    INSERT INTO
    Subtrandetails(correlatorid,PCORRELATORID ,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
    VALUES ('104','13','SAP1','blrkec95931d','10-DEC-07 07.24.07.042000 PM','10-DEC-07 07.31.07.042000 PM','Success');
    INSERT INTO
    Subtrandetails(correlatorid,PCORRELATORID,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
    VALUES ('105','13','SAP2','blrkec95931d','10-DEC-07 07.24.07.042000 PM','10-DEC-07 07.31.07.042000 PM','Success');
    INSERT INTO
    Subtrandetails(correlatorid,PCORRELATORID ,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
    VALUES ('106','13','SAP3','blrkec95931d','10-DEC-07 07.24.07.042000 PM','10-DEC-07 07.31.07.042000 PM','Success');
    INSERT INTO
    Subtrandetails(correlatorid,PCORRELATORID ,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
    VALUES ('107','13','SAP2','blrkec95931d','10-DEC-07 07.2.10.042350 PM','10-DEC-07 07.50.10.042050 PM','Success');
    INSERT INTO
    Subtrandetails(correlatorid,PCORRELATORID ,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
    VALUES ('108','11',' FINT3 ','blrkec95931d','10-DEC-07 07.16.07.042000 PM','10-DEC-07 07.53.09.042000 PM','Success');
    INSERT INTO
    Subtrandetails(correlatorid,PCORRELATORID ,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
    VALUES ('109','108','FINT3','blrkec95931d','10-DEC-07 07.20.07.042000 PM','10-DEC-07 07.59.09.042000 PM','Success');
    INSERT INTO
    Subtrandetails(correlatorid,PCORRELATORID ,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
    VALUES ('110','108','FINT3','blrkec95931d','10-DEC-07 07.18.07.042000 PM','10-DEC-07 07.57.09.042000 PM','Success');
    INSERT INTO
    Subtrandetails(correlatorid,PCORRELATORID ,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
    VALUES ('111','108','FINT4','blrkec95931d','10-DEC-07 07.18.07.042000 PM','10-DEC-07 07.57.09.042000 PM','Success');
    INSERT INTO
    Subtrandetails(correlatorid,PCORRELATORID ,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
    VALUES ('112','108','FINT5','blrkec95931d','10-DEC-07 07.18.07.042000 PM','10-DEC-07 07.57.09.042000 PM','Success');
    INSERT INTO
    Subtrandetails(correlatorid,PCORRELATORID ,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
    VALUES ('113','108','FINT6','blrkec95931d','10-DEC-07 07.18.07.042000 PM','10-DEC-07 07.57.09.042000 PM','Success');
    INSERT INTO
    Subtrandetails(correlatorid,PCORRELATORID ,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
    VALUES ('114','108','FINT7','blrkec95931d','10-DEC-07 07.18.07.042000 PM','10-DEC-07 07.57.09.042000 PM','Success');
    ======================================
    Thanks.

  • Help needed in select query to take date

    Hello,
    I am using Oracle 11g.
    I am using this query
    select to_date(to_char(to_date((SOURCE_MONTH||'-'||SOURCE_YEAR),'MM-YYYY'),'Mon-YYYY'),'MON-YYYY') date_
    from tab1 a,tab2 b
    where b.col2=a.col1;
    I have a table with 2 separate varchar columns month and year,
    I want to insert the data into another table which has the col type as timestamp.
    This query gives me the data as
    01-NOV-06 but
    i want the data as
    01-NOV-2006
    What should i do for that?
    Thanks

    First, get rid of the extra conversions from date to char and back to date:
    select to_date((SOURCE_MONTH||'-'||SOURCE_YEAR),'MM-YYYY'),'Mon-YYYY')
    from tab1 a,tab2 b
    where b.col2=a.col1;Now, your data is safely rendered as a DATE. It knows the full year (i.e.2006). You are just not seeing it formatted the way you like. You could
    alter session set nls_date_format = 'mm/dd/yyyy hh24:mi:ss';or give the explicit format you want when you query it (with TO_CHAR).
    Please read and understand about DATE datatypes....
    http://download.oracle.com/docs/cd/B28359_01/server.111/b28286/sql_elements001.htm#i54330
    In particular, search that page for: "DATE Datatype "

  • Need some help with the Select query.

    Need some help with the Select query.
    I had created a Z table with the following fields :
    ZADS :
    MANDT
    VKORG
    ABGRU.
    I had written a select query as below :
    select single vkorg abgru from ZADS into it_rej.
    IT_REJ is a Work area:
    DATA : BEGIN OF IT_REJ,
            VKORG TYPE VBAK-VKORG,
            ABGRU TYPE VBAP-ABGRU,
           END OF IT_REJ.
    This is causing performance issue. They are asking me to include the where condition for this select query.
    What should be my select query here?
    Please suggest....
    Any suggestion will be apprecaiated!
    Regards,
    Developer

    Hello Everybody!
    Thank you for all your response!
    I had changes this work area into Internal table and changed the select query. PLease let me know if this causes any performance issues?
    I had created a Z table with the following fields :
    ZADS :
    MANDT
    VKORG
    ABGRU.
    I had written a select query as below :
    I had removed the select single and insted of using the Structure it_rej, I had changed it into Internal table 
    select vkorg abgru from ZADS into it_rej.
    Earlier :
    IT_REJ is a Work area:
    DATA : BEGIN OF IT_REJ,
    VKORG TYPE VBAK-VKORG,
    ABGRU TYPE VBAP-ABGRU,
    END OF IT_REJ.
    Now :
    DATA : BEGIN OF IT_REJ occurs 0,
    VKORG TYPE VBAK-VKORG,
    ABGRU TYPE VBAP-ABGRU,
    END OF IT_REJ.
    I guess this will fix the issue correct?
    PLease suggest!
    Regards,
    Developer.

  • Help needed for writing query

    help needed for writing query
    i have the following tables(with data) as mentioned below
    FK*-foregin key (SUBJECTS)
    FK**-foregin key (COMBINATION)
    1)SUBJECTS(table name)     
    SUB_ID(NUMBER) SUB_CODE(VARCHAR2) SUB_NAME (VARCHAR2)
    2           02           Computer Science
    3           03           Physics
    4           04           Chemistry
    5           05           Mathematics
    7           07           Commerce
    8           08           Computer Applications
    9           09           Biology
    2)COMBINATION
    COMB_ID(NUMBER) COMB_NAME(VARCHAR2) SUB_ID1(NUMBER(FK*)) SUB_ID2(NUMBER(FK*)) SUB_ID3(NUMBER(FK*)) SUBJ_ID4(NUMBER(FK*))
    383           S1      9           4           2           3
    384           S2      4           2           5           3
    ---------I actually designed the ABOVE table also like this
    3) a)COMBINATION
    COMB_ID(NUMBER) COMB_NAME(VARCHAR2)
    383           S1
    384           S2
    b)COMBINATION_DET
    COMBDET_ID(NUMBER) COMB_ID(FK**) SUB_ID(FK*)
    1               383          9
    2               383          4
    3               383          2
    4               383          3
    5               384          4
    6               384          2          
    7               384          5
    8               384          3
    Business rule: a combination consists of a maximum of 4 subjects (must contain)
    and the user is less relevant to a COMB_NAME(name of combinations) but user need
    the subjects contained in combinations
    i need the following output
    COMB_ID COMB_NAME SUBJECT1 SUBJECT2      SUBJECT3      SUBJECT4
    383     S1     Biology Chemistry      Computer Science Physics
    384     S2     Chemistry Computer Science Mathematics Physics
    or even this is enough(what i actually needed)
    COMB_ID     subjects
    383           Biology,Chemistry,Computer Science,Physics
    384           Chemistry,Computer Science,Mathematics,Physics
    you can use any of the COMBINATION table(either (2) or (3))
    and i want to know
    1)which design is good in this case
    (i think SUB_ID1,SUB_ID2,SUB_ID3,SUB_ID4 is not a
    good method to link with same table but if 4 subjects only(and must) comes
    detail table is not neccessary )
    now i am achieving the result by program-coding in C# after getting the rows from oracle
    i am using oracle 9i (also ODP.NET)
    i want to know how can i get the result in the stored procedure itsef.
    2)how it could be designed in any other way.
    any help/suggestion is welcome
    thanks for your time --Pradeesh

    Well I forgot the table-alias, here now with:
    SELECT C.COMB_ID
    , C.COMB_NAME
    , (SELECT SUB_NAME
    FROM SUBJECTS
    WHERE SUB_ID = C.SUB_ID1) AS SUBJECT_NAME1
    , (SELECT SUB_NAME
    FROM SUBJECTS
    WHERE SUB_ID = C.SUB_ID2) AS SUBJECT_NAME2
    , (SELECT SUB_NAME
    FROM SUBJECTS
    WHERE SUB_ID = C.SUB_ID3) AS SUBJECT_NAME3
    , (SELECT SUB_NAME
    FROM SUBJECTS
    WHERE SUB_ID = C.SUB_ID4) AS SUBJECT_NAME4
    FROM COMBINATION C;
    As you need exactly 4 subjects, the columns-solution is just fine I would say.

  • I need a select query

    I have a dataset like below in two columns ( col1,col2 in table Mytable)
    A | ab
    A | cd
    A | ef
    B | xl
    B | ik
    E | 23
    E | op
    C | tk
    I need a select query which will return first set of every group which I ask for .
    For example, if I ask for data for A , B , the select query will return records
    A | ab
    B | xl
    For example, if I ask for data for B ,E the select query will return records..
    B | xl
    E | 23
    For example, if I ask for data for C the select query will return records..
    C | tk
    How do I write my select query ?

    Something like this ?
    SCOTT@orcl> create table test(col1 varchar2(1),col2 varchar2(2));
    Table created.
    SCOTT@orcl> insert into test values('A','ab');
    1 row created.
    SCOTT@orcl> insert into test values('A','cd');
    1 row created.
    SCOTT@orcl> insert into test values('A','ef');
    1 row created.
    SCOTT@orcl> insert into test values('B','xl');
    1 row created.
    SCOTT@orcl> insert into test values('B','ik');
    1 row created.
    SCOTT@orcl> insert into test values('E','23');
    1 row created.
    SCOTT@orcl> insert into test values('E','op');
    1 row created.
    SCOTT@orcl> insert into test values('C','tk');
    1 row created.
    SCOTT@orcl> commit;
    Commit complete.
    SCOTT@orcl>
    SCOTT@orcl> ed
    Wrote file afiedt.buf
      1  select * from (
      2  select decode(lag(col1) over (order by col1,rownum),null,col1
      3  ,col1,null
      4  ,col1) col1
      5  ,col2
      6  from test) aaa
      7* where aaa.col1='A'
    SCOTT@orcl> /
    C CO
    A abHTH
    Girish Sharma

  • I need help with a SELECT query - help!

    Hello, I need help with a select statement.
    I have a table with 2 fields as shown below
    Name | Type
    John | 1
    John | 2
    John | 3
    Paul | 1
    Paul | 2
    Paul | 3
    Mark | 1
    Mark | 2
    I need a query that returns everything where the name has type 1 or 2 but not type 3. So in the example above the qery should bring back all the "Mark" records.
    Thanks,
    Ian

    Or, if the types are sequential from 1 upwards you could simply do:-
    SQL> create table t as
      2  select 'John' as name, 1 as type from dual union
      3  select 'John',2 from dual union
      4  select 'John',3 from dual union
      5  select 'Paul',1 from dual union
      6  select 'Paul',2 from dual union
      7  select 'Paul',3 from dual union
      8  select 'Paul',4 from dual union
      9  select 'Mark',1 from dual union
    10  select 'Mark',2 from dual;
    Table created.
    SQL> select name
      2  from t
      3  group by name
      4  having count(*) <= 2;
    NAME
    Mark
    SQL>Or another alternative if they aren't sequential:
    SQL> ed
    Wrote file afiedt.buf
      1  select name from (
      2    select name, max(type) t
      3    from t
      4    group by name
      5    )
      6* where t < 3
    SQL> /
    NAME
    Mark
    SQL>Message was edited by:
    blushadow

  • Help in Join Select Query

    Hi, Please help on the Select Join query. I want to compare code_stat_system1/code_stat_system2 and code_date_system1 /code_date_system2 column from table #system1 and #system2 but there is 2 rule to get correct row from table #system1 and #system2.
    Rule 1: We need to get max(code_date_system1) record from #system1  for every code_system1 for compare.
    Rule 1: We need to get max(code_date_system2) record from #system2  BUT BEFORE THE RECORD OF 'DKNOW' OF code_stat_system2 for every code_system2 for compare.
    drop table #system1,#system2
    create table #system1
    (Code_system1 varchar(10),code_stat_system1 varchar(10),code_date_system1 datetime)
    Insert into #system1 values ('10','Dead','2013-01-01')
    Insert into #system1 values ('10','Dead','2013-12-30')
    Insert into #system1 values ('10','UnOpen','2014-10-01')
    Insert into #system1 values ('10','Open','2014-11-01')   --This record should max(code_stat_system1) for compare
    Insert into #system1 values ('20','Dead','2013-12-01')
    Insert into #system1 values ('20','Dead','2013-12-30')
    Insert into #system1 values ('20','Open','2014-08-01')
    Insert into #system1 values ('20','UnOpen','2014-09-01') --This record should max(code_stat_system1) for compare
    create table #system2
    (Code_system2 varchar(10),code_stat_system2 varchar(10),code_date_system2 datetime)
    Insert into #system2 values ('10','Dead','2013-01-01')
    Insert into #system2 values ('10','Dead','2013-12-30')
    Insert into #system2 values ('10','Open','2014-10-01')
    Insert into #system2 values ('10','UnOpen','2014-12-01') --This record should max(code_stat_system2) which is before 'DKNOW' for compare
    Insert into #system2 values ('10','DKNOW','2015-01-01')
    Insert into #system2 values ('10','DKNOW','2015-02-01')
    Insert into #system2 values ('20','Dead','2013-12-01')
    Insert into #system2 values ('20','Dead','2013-12-30')
    Insert into #system2 values ('20','Open','2014-08-01')
    Insert into #system2 values ('20','UnOpen','2014-09-01') --This record should max(code_stat_system2) which is before 'DKNOW' for compare
    Insert into #system2 values ('20','DKNOW','2015-01-01')
    Insert into #system2 values ('20','DKNOW','2015-02-01')
    --Desired Output
    Code_system1  code_stat_system1  code_date_system1  Code_system1   code_stat_system2  code_date_system1    Rrmk_code_stat         Rrmk_code_date
    10            Open           2014-11-01        10          UnOpen         
    2014-12-01         Codes not matching     Dates not matching
    20            UnOpen         2014-09-01        20          UnOpen         
    2014-09-01         Codes matching          Dates matching
    Thanks.

    drop table #system1,#system2
    create table #system1
    (Code_system1 varchar(10),code_stat_system1 varchar(10),code_date_system1 datetime)
    Insert into #system1 values ('10','Dead','2013-01-01')
    Insert into #system1 values ('10','Dead','2013-12-30')
    Insert into #system1 values ('10','UnOpen','2014-10-01')
    Insert into #system1 values ('10','Open','2014-11-01') --This record should max(code_stat_system1) for compare
    Insert into #system1 values ('20','Dead','2013-12-01')
    Insert into #system1 values ('20','Dead','2013-12-30')
    Insert into #system1 values ('20','Open','2014-08-01')
    Insert into #system1 values ('20','UnOpen','2014-09-01') --This record should max(code_stat_system1) for compare
    create table #system2
    (Code_system2 varchar(10),code_stat_system2 varchar(10),code_date_system2 datetime)
    Insert into #system2 values ('10','Dead','2013-01-01')
    Insert into #system2 values ('10','Dead','2013-12-30')
    Insert into #system2 values ('10','Open','2014-10-01')
    Insert into #system2 values ('10','UnOpen','2014-12-01') --This record should max(code_stat_system2) which is before 'DKNOW' for compare
    Insert into #system2 values ('10','DKNOW','2015-01-01')
    Insert into #system2 values ('10','DKNOW','2015-02-01')
    Insert into #system2 values ('20','Dead','2013-12-01')
    Insert into #system2 values ('20','Dead','2013-12-30')
    Insert into #system2 values ('20','Open','2014-08-01')
    Insert into #system2 values ('20','UnOpen','2014-09-01') --This record should max(code_stat_system2) which is before 'DKNOW' for compare
    Insert into #system2 values ('20','DKNOW','2015-01-01')
    Insert into #system2 values ('20','DKNOW','2015-02-01')
    ;with mycte1 as (select * ,row_number() Over (partition by Code_system1 Order by code_date_system1 Desc ) rn from #system1)
    ,mycte2 as (select *,row_number() Over (partition by Code_system2 Order by code_date_system2 Desc ) rn2 from #system2
    where code_stat_system2<>'DKNOW')
    Select m1.Code_system1, m1.code_stat_system1, m1.code_date_system1, Code_system2, code_stat_system2,code_date_system2 ,
    case When code_date_system1=code_date_system2 then 'Dates matching' else 'Dates not matching' End as checkDate,
    case When code_stat_system1=code_stat_system2 then 'Codes matching' else 'Codes not matching' End as checkStat
    from mycte1 m1 inner join mycte2 m2 on m1.Code_system1= m2.Code_system2 and m1.rn=m2.rn2
    Where m1.rn=1

  • Help regarding a select Query

    hi All,
    I have one requirement.I wonder whether i can do it in a single SQL Statement or not.
    I have tab1 with columns c1,c2,c3,c4,....,Logon_time
    I have tab2 with columns C1,c2,c3,c4.....,Logoff_time
    All the columns are same for two tables except that logon_time and logoff_time as mentioned above.
    tab1 will have all the information of user who logon to database.
    tab2 will have all the information of user who logoff from DB.
    Now i i have to generate a report which shows all the user info and logon Duration.For that i can use logoff_time - logon_time.but the challenge here is logoff_time dont contain rows for the users who logon to database byt yet to logoff.
    So for them logoff_time-logon_time showing -ve Duration.
    So I want Duration as logoff_time-logon_time for all the rows.But for those users who yet to logoff i want duration as "YET to Logoff"
    Is this possible with single Select Query.
    Thanks
    Pramod

    Hi, Pramod,
    You need to join tab_1 to tab_2. Since not every row in tab_1 will have a matching row in tab_2, make it an outer join.
    How do you know which row in tab_1 matches which row in tab_2?
    I assume there's some column (let's say c1) that identifies a user. A user can have several sessions going at the same time, however.
    The following query matches the n-th logon_time in tab_1 with the n-th logoff_time in tab_2 for the same user:
    WITH     numbered_tab_1     AS
         SELECT  c1, c2, c3, c4, ..., logon_time
         ,     ROW_NUMBER () OVER ( PARTITION BY  c1     -- or whatever identifies user
                                   ORDER BY          logon_time
                           ) AS r_num
         FROM     tab_1
    ,     numbered_tab_2     AS
         SELECT  c1, c2, c3, c4, ..., logon_time
         ,     ROW_NUMBER () OVER ( PARTITION BY  c1     -- or whatever identifies user
                                   ORDER BY          logoff_time
                           ) AS r_num
         FROM     tab_2
    SELECT     t1.c1, t1.c2, t1.c3, t1.c4, ..., t1.logon_time     -- or whatever you want
    ,     t2.c1, t2.c2, t2.c3, t2.c4, ..., t2.logoff_time
    ,     NVL ( TO_CHAR (24 * (t2.logff_time - t1.logon_time))    -- duration in hours
             , 'Yet to Logoff'
             )         AS duration
    FROM             numbered_tab_1     t1
    LEFT OUTER JOIN     numbered_tab_2     t2     ON   t1.c1     = t2.c1
                                     AND  t1.r_num  = t2.r_num
    ;I can test this if you'll post some sample data and the results you want from that data.
    The query above matches logons and logoffs only by user and time
    For example, say I log on at 10:00.
    At 10:45, I open another window and log on again, but log off at 10:50 after 5 minutes.
    At 11:30 I log off the first session.
    If you were interested in sessions that lasted over 1 hour, the query above would not be accurate. It would show one session starting at 10:00 and ending at 10:50, and another session starting at 10:45 and ending at 11:30. To know that the first session to end was the second sessiion in order of beginning, you would have to have another column, say a unique session id.
    If you're only interested in the number of sessions, or the total time connected per user, then the query above will be good enough.
    Edited by: Frank Kulash on Jul 6, 2009 12:07 PM

  • Help need in a query

    Could you please get me with a select query for getting my expected result.
    I tried to use group function in my query, but it giving all the user_id if i group, so please help me on this.
    user_id trann_name resp_time
    1 dog 0.5
    2 dog 1.0
    3 dog 0.6
    4 dd 0.4
    5 cat 0.3
    expected result:
    1 dog 0.5
    4 dd 0.4
    5 cat 0.3
    Thanks.

    Blu, that is obviously wrong ;-)
    OP wants (The ones with the fastest response time):
    SQL> with test_data as (select 1 user_id, 'dog' trann_name, 0.5 resp_time from dual union all
                       select 2 user_id, 'dog' trann_name, 1.0 resp_time from dual union all
                       select 3 user_id, 'dog' trann_name, 0.6 resp_time from dual union all
                       select 4 user_id, 'dd'  trann_name, 0.4 resp_time from dual union all
                       select 5 user_id, 'cat' trann_name, 0.3 resp_time from dual)
    -- End of test data, below is actual query
    select max(user_id) keep (dense_rank first order by resp_time) user_id,
           trann_name,
           min(resp_time) resp_time
      from test_data
    group by trann_name
    order by user_id
       USER_ID TRANN_NAME  RESP_TIME
             1 dog                ,5
             4 dd                 ,4
             5 cat                ,3
    3 rows selected.Best regards
    Peter

  • Pls help me in select query......

    My problem is...
    I have to use a select query in such a manner  that i  can compare the last 8 characters or ignore the first one...

    Hi Aarif,
    Try this :
    parameters :
      p_field1(30)  type c.
    Data :
      w_string(8) type c,
      w_firstchar type c,
      t_itab ......,
      fs_itab like line of itab.
    w_string = p_field1+22(8)      " passing last 8 chars into w_string
    w_firstchar = p_field1+0(1).
    select *
       from DataTab Name
       into  table IntTab Name
    where <field name> eq w_string
          or  <field name> ne w_firstchar.
    If you are accepting the value from user then first pass the last 8 characters into w_string and in your select query get the fields where the value is equal to w_string. And pass the first character into another field and to ignore write NE W_FIRSTCHAR.
    There can be other methods also. This is one of the ways.
    Regards,
    Swapna.
    Edited by: NagaSwapna Thota on Jul 19, 2008 9:23 AM

  • 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?

  • Help needed for SQL query

    hello ,
    I am a beginner in terms of writing sql queries. I hope some body can help me out.
    I have two tables
    mysql> desc user_group_t;
    ---------------------------------------------------+
    | Field | Type | Null | Key | Default | Extra |
    ---------------------------------------------------+
    | userAccountId | char(8) | | PRI | | |
    | groupId | char(8) | | PRI | | |
    ---------------------------------------------------+
    2 rows in set (0.00 sec)
    mysql> desc group_t;
    ---------------------------------------------------+
    | Field | Type | Null | Key | Default | Extra |
    ---------------------------------------------------+
    | id | char(8) | | PRI | | |
    | name | char(50) | YES | | NULL | |
    | email | char(100) | YES | | NULL | |
    | description | char(254) | YES | | NULL | |
    | parentId | char(8) | YES | | NULL | |
    | creatorId | char(8) | YES | | NULL | |
    | createDate | char(20) | YES | | NULL | |
    | updateDate | char(20) | YES | | NULL | |
    | updatorId | char(8) | YES | | NULL | |
    ---------------------------------------------------+
    9 rows in set (0.00 sec)
    what I want is list of all groups with id,name and #of members(which is the # of rows in the user_group_t for any given id). Importantly I need the groups with 0 members also to be listed. In short my output should contain exactly the same number of rows as in group_t table with an additional column indicating # of members for that group.
    Any help would be greatly appreciated.
    Thanks in Advance.
    -Vasanth

    Thanks Donald,
    Actually I figured it out, with the following query:
    select id,name,sum(if(groupid is not null,1,0)) as members from group_t left join user_group_t on id=groupid group by id;
    I tried your solution, but mysql says there is an error at '+' . Anyway I modified your solution to the one below and it worked.
    select a.id, a.name, count(b.groupid) from group_t a left join user_group_t b on a.id=b.groupid group by a.id, a.name;
    I tried that before but then I used Count(*) instead of count on groupid. Your solution is elagant and I will go with yours.
    Thanks again.
    Vasanth

  • Urgent help needed on 1 query

    Hello All,
    I have just started working in PL/SQL,
    I need some help on 1 urgent issue.
    i have a table lets say which has structure and values like below:
    ID Data Key Data Value
    1 Firstname X
    2 Lastname Y
    3 Middlename Z
    but my query shd return me data having firstname ,middlenale and last name as column names and lvalues like lsited below:
    Firstname Middlename Lastname
    X Y Z
    Please help and i really appreciate for your time and help!!!!!!!!!!
    Thanks and Regards

    Urgent? I don't think so.
    However, as others have mentioned, what groups the items together so that the relationship is known between them?
    SQL> ed
    Wrote file afiedt.buf
      1  with t as (select 1 as id, 'Firstname' as data_key, 'Fred' as data_val from dual union all
      2             select 2, 'Surname', 'Bloggs' from dual union all
      3             select 3, 'Middlename', 'J' from dual union all
      4             select 4, 'Firstname', 'John' from dual union all
      5             select 5, 'Surname', 'Doe' from dual union all
      6             select 6, 'Middlename', 'D' from dual)
      7  --
      8  select id-decode(data_key,'Surname',1,'Middlename',2,0) as id
      9        ,max(decode(data_key,'Firstname',data_val)) as Firstname
    10        ,max(decode(data_key,'Middlename',data_val)) as Middlename
    11        ,max(decode(data_key,'Surname',data_val)) as Surname
    12  from t
    13* group by id-decode(data_key,'Surname',1,'Middlename',2,0)
    SQL> /
            ID FIRSTN MIDDLE SURNAM
             1 Fred   J      Bloggs
             4 John   D      Doe
    SQL>This example assumes that a Firstname, Surname and Middlename appear in that order with sequential ID's, such that the ID for Surname is always 1 more than the ID for it's associated Forename and the ID for Middlename is always 2 more than the associated Forename.

  • Help needed in a Query

    I have a table TAB that has two colums. COL1 and COL2. Both are composite Primary key.
    The data is as
    COL1 COL2
    1 C
    2 C
    3 C
    4 G
    5 G
    1 G
    3 G
    6 G
    7 G
    I need to find out those COL1 values whose COL2 values are C and G. Ex
    COL1 COL2
    1 C
    3 C
    1 G
    3 G
    So i need the following op
    COL1
    1
    3
    Please help me to solve this query.
    Regards.
    Message was edited by:
    SID

    and what have you tried ????
    SQL> With t As
      2    (
      3    Select 1 c1, 'C' c2 From DUAL Union All
      4    Select 2,     'C'   From DUAL Union All
      5    Select 3,     'C'   From DUAL Union All
      6    Select 4,     'G'   From DUAL Union All
      7    Select 5,     'G'   From DUAL Union All
      8    Select 1,     'G'   From DUAL Union All
      9    Select 3,     'G'   From DUAL Union All
    10    Select 6,     'G'   From DUAL Union All
    11    Select 7,     'G'   From DUAL
    12    )
    13    Select t.c1, t.c2
    14    From
    15    t,
    16    (
    17    Select c1, c2
    18    From t
    19    Where c2 = 'C'
    20    ) c,
    21    (Select c1, c2
    22     From t
    23     Where c2 = 'G'
    24     ) g
    25  Where t.c1 = c.c1
    26  And   t.c1 = g.c1
    27  --And   c.c2 = g.c2;
            C1 C2
             1 C
             1 G
             3 C
             3 G
    SQL>
    /*using analytical functons*/
    SQL>
    SQL> With t As
      2    (
      3    Select 1 c1, 'C' c2 From DUAL Union All
      4    Select 2,     'C'   From DUAL Union All
      5    Select 3,     'C'   From DUAL Union All
      6    Select 4,     'G'   From DUAL Union All
      7    Select 5,     'G'   From DUAL Union All
      8    Select 1,     'G'   From DUAL Union All
      9    Select 3,     'G'   From DUAL Union All
    10    Select 6,     'G'   From DUAL Union All
    11    Select 7,     'G'   From DUAL
    12    )
    13   select c1, c2
    14         from ( select c1,c2, case when c2 = 'C' then count(decode(c2,'G',1)) over (partition by c1)
    15                                    when c2 = 'G' then count(decode(c2,'C',1)) over (partition by c1)
    16                               else 0 end count                           
    18                from t
    19            )
    20      where Count != 0
    21  /
            C1 C2
             1 C
             1 G
             3 C
             3 GMessage was edited by:
    Nicloei W

Maybe you are looking for

  • Digital camera setup not working

    Hi, My computer all of the sudden is not reading my camera when pluged into the usb. In the past I was able to use my camera with the usb. My computer (flat screen G4) Although is able to read my ipod with no problems. I tried all three usb ports in

  • Graphs not shown in EXCEL, when the reports server is secured with SSL

    We installed a SSL certificate on the reports server to run as https instead of http and the graphs in the reports stopped working for desformat=EXCEL. The graphs in the pdf output run fine.the version we are using is Oracle reports 10g

  • EDI 830/860 problem

    Hi My scenario from EDI  Files to IDOC and we are sending some value to the TXT01 field in IDOC DELFOR01. We are mapping an UDF with TXT01 field. The UDF have code: if (txtTwo.equals(""))     result.addValue(result.SUPPRESS); else    result.addValue(

  • TEXT_CONVERT_XLS_TO_SAP error

    Hi friends i am using the following FM FORM GET_MAT_FROM_SPREAD .     CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'     EXPORTING     I_FIELD_SEPERATOR        =       i_line_header            =  'X'       i_tab_raw_data           =  it_raw       " WORK TAB

  • UpdateRow problem...

    Hi all, It's my first time try using JDBC 2.0 API, here is the problem: If I use: uprs.last(); uprs.updateFloat("PRICE", 10.99f); uprs.updateRow(); Ok, It's no problem at all, but when I using: uprs.getString(1); uprs.last(); uprs.updateFloat("PRICE"