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

Similar Messages

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

  • Regarding the select query

    Hi Experts,
    I have a select query as follows:
    select field1 field2  from db1 into table it1.
    Now suppose the it1-field1 contains values a,b and c.
    Now I want to select fields a,b and c from another db table db2.
    Instead of hard coding like this:
    select a b c from db2 into table it2.....
    How can I do this?
    Points will be awarded.
    Regards,
    Soumya.

    Hi Soumya ,
    Pleas use FOR ALL ENTRIES syntax , in this way you can select the records from db2 which are available or selected in db1.
    Like Header And Item table.
    You select records frm header table . then for corres ponding header records you select from detail table db2 .....
    Condition is the field containg a,b,c  is key field in both tables ...
    Reward points if it helps you .
    Regards
    Amber S

  • 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

  • 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

  • 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

  • Help in Pivot select Query

    Hello,
    Oracle:Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
    OS: Windows XP SP-3
    create table dws(coll_cd varchar2(6),tot float,dtcd varchar2(2),distname varchar2(20),schtype varchar2(1),year varchar2(4));
    insert into dws values('01001',103,'01','DIST1','1','2008');
    insert into dws values('01001',23,'01','DIST1','1','2007');
    insert into dws values('01115',39,'02','DIST2','2','2008');
    insert into dws values('01715',39,'02','DIST2','1','2007');
    insert into dws values('01415',120,'02','DIST2','2','2008');
    insert into dws values('01749',200,'01','DIST1','1','2006');
    insert into dws values('01449',200,'01','DIST1','2','2006');
    Year column will contain only 2006,2007 and 2008 and only 1,2 in schtype column.
    Output required: (Count of records as per year and schtype group by dtcd)
                                         2008                          2007                             2006
    DTCD    DISTNAME           TYPE1     TYPE2     TOTAL      TYPE1    TYPE2     TOTAL         TYPE1    TYPE2    TOTAL
    01      DIST1                1         0         1          1        0         1             1       1        2      
    02      DIST2                0         2         2          1        0         1             0       0        0I tried by following:
    select dtcd,
    sum(case when(year='2008' and schtype='1') then 1 else 0 end) A,
    sum(case when(year='2008' and schtype='2') then 1 else 0 end) B,
    sum(case when(year='2007' and schtype='1') then 1 else 0 end) C,
    sum(case when(year='2007' and schtype='2') then 1 else 0 end) D,
    sum(case when(year='2006' and schtype='1') then 1 else 0 end) E,
    sum(case when(year='2006' and schtype='2') then 1 else 0 end) F
    from dws group by dtcd,govtpvtn order by 1
    but it is not which i want.
    Please help me how to write the query to get the required output.
    Thanks & Regards
    Girish Sharma
    Edited by: Girish Sharma on Dec 22, 2008 10:28 PM

    There could be several ways to frame this query. One of the ways could be as follows:
    SELECT
    DTCD,
    DISTNAME,
    (SELECT COUNT(1) FROM DWS B WHERE A.DTCD = B.DTCD AND A.DISTNAME = B.DISTNAME AND B.YEAR = '2008' AND B.SCHTYPE = '1') TYPE1_2008,
    (SELECT COUNT(1) FROM DWS B WHERE A.DTCD = B.DTCD AND A.DISTNAME = B.DISTNAME AND B.YEAR = '2008' AND B.SCHTYPE = '2') TYPE1_2008,
    (SELECT COUNT(1) FROM DWS B WHERE A.DTCD = B.DTCD AND A.DISTNAME = B.DISTNAME AND B.YEAR = '2008') TOTAL_2008,
    (SELECT COUNT(1) FROM DWS B WHERE A.DTCD = B.DTCD AND A.DISTNAME = B.DISTNAME AND B.YEAR = '2007' AND B.SCHTYPE = '1') TYPE1_2007,
    (SELECT COUNT(1) FROM DWS B WHERE A.DTCD = B.DTCD AND A.DISTNAME = B.DISTNAME AND B.YEAR = '2007' AND B.SCHTYPE = '2') TYPE1_2007,
    (SELECT COUNT(1) FROM DWS B WHERE A.DTCD = B.DTCD AND A.DISTNAME = B.DISTNAME AND B.YEAR = '2007') TOTAL_2007 ,
    (SELECT COUNT(1) FROM DWS B WHERE A.DTCD = B.DTCD AND A.DISTNAME = B.DISTNAME AND B.YEAR = '2006' AND B.SCHTYPE = '1') TYPE1_2006,
    (SELECT COUNT(1) FROM DWS B WHERE A.DTCD = B.DTCD AND A.DISTNAME = B.DISTNAME AND B.YEAR = '2006' AND B.SCHTYPE = '2') TYPE1_2006,
    (SELECT COUNT(1) FROM DWS B WHERE A.DTCD = B.DTCD AND A.DISTNAME = B.DISTNAME AND B.YEAR = '2006') TOTAL_2006   
    FROM
    DWS A
    GROUP BY DTCD, DISTNAME
    DT DISTNAME             TYPE1_2008 TYPE1_2008 TOTAL_2008 TYPE1_2007 TYPE1_2007 TOTAL_2007 TYPE1_2006 TYPE1_2006 TOTAL_2006   
    01 DIST1                         1          0          1          1          0          1          1          1          2   
    02 DIST2                         0          2          2          1          0          1          0          0          0   

  • 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 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 with nested select query

    Here is my code , i dont have any experience with writing the nested sql , i got the below code , which needs to be modified adding a case statement which will show util_rate for 2 conditions
    1. given in where condition ( to_char(time_stamp,'HH24') >= '09' and to_char(time_stamp,'HH24') <= '19')
    2.Apposite to the condition above (to_char(time_stamp,'HH24') < '09'and to_char(time_stamp,'HH24') > '19')
    could anybody please help me in adding the 2nd condition to the below query , please share any documentation you have for learning how to write nested sql,
    Thank you
    select device,time_stamp,
    sum(ActiveHRS)/sum(AvailHRS) as RATE
    from
    select device,time_stamp,
    case when usage >0 then 1
    else 0 end as ActiveHRS,
    '1' as AvailHRS
    from
    select device,time_stamp,
    sum(case
    when state = 9 then 0
    when state = 0 then 0
    else 1 end) as usage
    from A
    where to_char(time_stamp,'HH24') >= '09'
    and to_char(time_stamp,'HH24') <= '19'
    and to_char(time_stamp, 'D') in (2,3,4,5,6)
    group by device, time_stamp
    group by device,time_stamp

    Here is the DDL :
    desc rumi_all
    Name     Null   Type    
    RUMI_DEVICE      VARCHAR2(20)
    STATE         NUMBER(38) 
    TIME_STAMP      DATE     
    LOCATION       VARCHAR2(50) Here is some sample data :
    RUMI_DEVICE   STATE   TIME_STAMP    LOCATION
    10.45.28.86     0     15-JUN-10      WA-102
    10.45.28.51     0     15-JUN-10      WA-102
    10.45.28.63     0     15-JUN-10      WA-102
    10.45.29.47     9     15-JUN-10      WA-120I used the below query to get the util for the hours 9am - 7pm
    select rumi_device,time_stamp,
    sum(ActiveHRS)/sum(AvailHRS) as RATE
    from
    select rumi_device,time_stamp,
    case when usage >0 then 1
    else 0 end as ActiveHRS,
    '1' as AvailHRS
    from
    select rumi_device,time_stamp,
    sum(case
    when state = 9 then 0
    when state = 0 then 0
    else 1 end) as usage
    from rumi_all
    where to_char(time_stamp,'HH24') >= '09'
    and to_char(time_stamp,'HH24') <= '19'
    and to_char(time_stamp, 'D') in (2,3,4,5,6)
    group by rumi_device, time_stamp
    group by rumi_device,time_stamp
    Acquired Out for the above query :
    RUMI_DEVICE      TIME_STAMP     UTIL_RATE
    10.45.29.47     15-JUN-10       0.234
    10.45.28.63     15-JUN-10             0.123
    10.45.29.47     15-JUN-10             0.987
    10.45.29.47     16-JUN-10             0.23Desired output :I want 2 extra columns which shows util rate for the above condition i.e 9am - 7pm(core hours) and also opposite to that condition after 7pm - before 9am(say, non core hours)
    Desired out put :
    RUMI_DEVICE TIME_STAMP  Core_Util_Rate   Non_Core_UtilRate
    10.45.29.4    15-JUN-10       0.234              0.003
    10.45.28.63   15-JUN-10     0.123              0.001
    10.45.29.47   15-JUN-10              0.987              0.023
    10.45.29.47   16-JUN-10              0.23                  0Hope this helps in answering my question , and also could you please share some document to learn writing nested sql's , i always had tough time in understanding this :-(

  • Need help regarding "saving a query"

    Hi BW gurus,
    I have a few doubts.
    I developed few queries in the DEV and i transported to QA.
    Since DEV was not having much data i could visualize the report(graphical report) if it meets my reporting specs.
    So i made the query changes directly in the QA system, and i created a workbook,which contains plenty of Excel work and macros programming.Now my report is ready in QA.
    These are my doubts
    1.Can my queries and workbooks be transported to PROD without any problem from QA?
    2.I tried to make the similar changes to the queries in DEV ,and i tried to save it,but i got an error on the Query Designer window stating that,the query cannot be saved due to a problem in the transport?
    Tell me what are the ways to solve my problems
    Thanks in Advance,
    Have a nice day
    Regards
    SM

    Hi Sam,
    When you need to make any changes to any object BEx related or AWB objects, the changes have to be first made in the dev system and then transported to QA. If there is a difference between the QA and the dev system the transports might fail.
    And as you already got the solution. Create a BEx Transport Request in Transport Connection and then make the changes to the query and save. Then you can transport the same to qa and prod without any issue.
    How this helps.
    NewBW

  • Help reagrding the selection query

    Hi All...
    I have     VBELN
         LFART
         VKORG
         KUNNR
         ERDAT
         LFDAT
         VSTEL
         ROUTE in my selection-screen. All the fields are from LIKP.
    Now I need to add one more field LAND1 from the table VBPA in the selection screen.
    This is my logic to filter the previous requirement. Now how to validate the LAND1?
    -> LIKP
      select vbeln
              into table i_likp
              from likp
              where vbeln in s_vbeln
                and lfart in s_lfart
                and vkorg in s_vkorg
                and kunnr in s_kunnr
                and erdat in s_erdat
                and lfdat in s_lfdat
                and vstel = p_vstel
                and route in s_route.
      if sy-subrc = 0.
    -> LIPS
        select vbeln posnr bwtar volum
                into table i_lips
                from lips
                for all entries in i_likp
                where vbeln = i_likp-vbeln.
    Please help me in that. I will reward u with good points.
    Reagrds
    Arjun Jain

    For LAND1 validation do as below.
    AT SELECTION-SCREEN ON s_land1.
    SELECT land1 FROM t005
                           into t005-land1
                           where land1 IN s_land1.
    if sy-subrc NE 0.
    message e000 WITH 'Enter valid Land value'.
    endif.
    For the query u can use join
    select a~vbeln  b~posnr b~bwtar b~volum
             from likp as a inner join  lips as b
             on a~vbeln =b~vbeln
             into table i_tab
             where a~vbeln in s_vbeln
              and a~lfart in s_lfart
              and a~vkorg in s_vkorg
              and a~kunnr in s_kunnr
              and a~erdat in s_erdat
             and a~lfdat in s_lfdat
            and a~vstel = p_vstel
            and a~route in s_route.
    This will solve ur problem.
    U can reward for the helpful answers.

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

  • Help regarding applet for querying client's MAC?

    Please help with an applet and java code that uses Runtime.getRuntime().exec("ipconfig -all") and gets the client's machine MAC address?
    If any one already worked with applets for querying client mahchine MAC , please give me a solution.

    remus.dragos wrote:
    vasu.mtech wrote:
    I am giving an explanation where I want this:
    We have an application, where user will be given a specific machine(with one MAC) and have to login from there only. If he tries to login from different machine with same user id, we should throw an error message. That's concept. We know that this reduces/kills operatability of the user from different machines.
    But we shouldn't allow the user operating from diffrent machines.What happens if the admins NIC burns? And he gets a news one? He can't log in until you manually change his
    MAC in the database ???Database? That's not secure!
    It has to be hardcoded into the exe (guess what the kid's next question will be?).

  • 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

Maybe you are looking for

  • Material Document Tables

    Hello Gurus, In Migo_GR. How do I determine if a Material Document  is A01 Goods Receipt and R05 Outbound Delivery. I mean which tables do I need to refer to Rgds, Aryan

  • DUPLICAR PAGINA

    COMO PUEDO DUPLICAR UNA IMAGEN TAMAÑO CARTA A TAMAÑO TABLOIDE. TENGO ADOBE ACROBAT 6.0 STANDARD

  • How to use text-by-speech for N80?

    I have been reading some posts here and there, but I havent seen anywhere where it states that text by speech works or does not work for N80? I was hoping somebody coud tell me, if it does work how do you install it? Thank you so much

  • Dynamic Bin for delivery Transfer Order

    Dear All, We have WM implemented in our SAP landscape. We do the picking though transfer order created with reference to outbound delivery through LT03. In this picking transfer order the destination storage type is 916 and bin is dymanic bin (which

  • Made a little mistake.

    I've replaced my older iPod nano that broke awhile back with an iPod touch and just used the same account that I have been using. I put in the details to subscribe my ipod to itunes but put my age to 21 in case I had to make another email for a paren