Sql query/function problem??

Hi ,
I have problems writing a difficult sql query, please help me
I have a table t in which there are 50000 records
the table has columns like
create table t
(MATCH_ID     NUMBER(4) NOT NULL,
TEAM_ID NUMBER(4),
PLAYER_ID     NUMBER(4),
RUNS     NUMBER(3))
here match_id, player_id and team_id are jointly primary key
SQL> SELECT * FORM T WHERE MATCH_ID < 10
MATCH_ID    TEAM_ID      PL_ID RUNS
        1          2       1228 8
        1          2       1203 82
        1          2       1316 24
        1          1       1150 27
        1          1       1278 13
        1          1       1243 60
        2          1       1278 37
        2          1       1291 0
        2          1       1243 53
        2          2       1228 25
        2          2       1285 103
        2          2       1316 60
        3          2       1228 8
        3          2       1285 25
        3          2        858 43
        3          1       1278 52
        3          1       1394 6
        3          1       1243 31
        4          1       1278 61
        4          1       1394 6
        4          1       1243 3
        4          2       1228 41
        4          2       1285 40
        4          2        858 5
        6          2       1228 20
        6          2       1285 100
        6          2       1408 0
        7          2       1228 15
        7          2       1285 34
        7          2       1408 44
        8          2       1228 0
        8          2       1420 31
        8          2       1340 66
        9          2       1420 19
        9          2       1385 28
        9          2       1340 0
.....so on upto 50000 records..
the problem is that I want to extract how many times each player_id in each
match exists in the table, prior to that match_id (or current_match_id)
along with that in another column, I also want the sum of 'RUNS' for each
player_id  prior to that match_id (or current_match_id)
my disired output is:
MATCH_ID    TEAM_ID   player_ID RUNS   NO_OF_OCCURENCES    SUM(RUNS)
                                       BEFORE_THIS_MATCH   BEFORE_THIS_MATCH
                                       FOR_THIS_PLAYER_ID  FOR_THIS_PLAYER_ID
        1          2       1228 8      0                   0
        1          2       1203 82     0                   0
        1          2       1316 24     0                   0
        1          1       1150 27     0                   0
        1          1       1278 13     0                   0
        1          1       1243 60     0                   0
        2          1       1278 37     1                   13
        2          1       1291 0      0                   0
        2          1       1243 53     1                   60
        2          2       1228 25     1                   8
        2          2       1285 103    0                   0
        2          2       1316 60     1                   24
        3          2       1228 8      2                   33
        3          2       1285 25     1                   103
        3          2        858 43     0                   0
        3          1       1278 52     2                   50
        3          1       1394 6      0                   0
        3          1       1243 31     2                   113
        4          1       1278 61     3                   102
        4          1       1394 6      1                   6
        4          1       1243 3      3                   144
        4          2       1228 41     3                   41
        4          2       1285 40     2                   128
        4          2        858 5      1                   43
        6          2       1228 20     4                   82
        6          2       1285 100    3                   168
        6          2       1408 0      0                   0
        7          2       1228 15     5                   102
        7          2       1285 34     4                   268
        7          2       1408 44     1                   0
        8          2       1228 0      6                   117
        8          2       1420 31     0                   0
        8          2       1340 66     0                   0
        9          2       1420 19     1                   31
        9          2       1385 28     0                   0
        9          2       1340 0      1                   66
as you can see from the above data (5TH COLUMN), i have mentioned the
existance of each player_id in each match prior to the current_match_id
since match_id = 1 is the 1st match in the table so no player_id comes in the
table before match number 1.   
In match number 2 , player_id = 1278 was also present in match_id = 1 so
thats why Number_OF_OCCURENCES = 1 for  player_id = 1278 in match_id = 2
and so on..
same is the case with 'RUNS' column but here RUNS are the SUM of each
player_id's 'RUNS' before the current match
Note: if some player_id does not exist in the table before the current
match_ID then the query should return zero for that player_id ( as in 4th and
5th columns of no_of_occurances and sum(runs) respectively)
for example: in above data
MATCH_ID    TEAM_ID  PLayer_ID RUNS   NO_OF_OCCURENCES    SUM(RUNS)
                                      BEFORE_THIS_MATCH   BEFORE_THIS_MATCH
                                      FOR_THIS_PLAYER_ID  FOR_THIS_PLAYER_ID
       9          2       1385 28     0                   0
I hope this will clear my problem
i would be extremely grateful if someone helps me out??
here is sample ddl of the above data
create table t
(MATCH_ID     NUMBER(4) NOT NULL,
TEAM_ID         NUMBER(4),
PLAYER_ID     NUMBER(4),
RUNS     NUMBER(3))
insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (1, 2, 1228, 8);
insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (1, 2, 1203, 82);
insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (1, 2, 1316, 24);
insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (1, 1, 1150, 27);
insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (1, 1, 1278, 13);
insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (1, 1, 1243, 60);
insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (2, 1, 1278, 37);
insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (2, 1, 1291, 0);
insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (2, 1, 1243, 53);
insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (2, 2, 1228, 25);
insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (2, 2, 1285, 103);
insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (2, 2, 1316, 60);
insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (3, 2, 1228, 8);
insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (3, 2, 1285, 25);
insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (3, 2, 858, 43);
insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (3, 1, 1278, 52);
insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (3, 1, 1394, 6);
insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (3, 1, 1243, 31);
insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (4, 1, 1278, 61);
insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (4, 1, 1394, 6);
insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (4, 1, 1243, 3);
insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (4, 2, 1228, 41);
insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (4, 2, 1285, 40);
insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (4, 2, 858, 5);
insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (6, 2, 1228, 20);
insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (6, 2, 1285, 100);
insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (6, 2, 1408, 0);
insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (7, 2, 1228, 15);
insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (7, 2, 1285, 34);
insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (7, 2, 1408, 44);
insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (8, 2, 1228, 0);
insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (8, 2, 1420, 31);
insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (8, 2, 1340, 66);
insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (9, 2, 1420, 19);
insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values  (9, 2, 1385, 28);
insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (9, 2, 1340, 0);regards
ramis.

Ramis,
SQL> select * from tt;
  MATCH_ID    TEAM_ID  PLAYER_ID       RUNS
         1          2       1228          8
         1          2       1203         82
         1          2       1316         24
         1          1       1150         27
         1          1       1278         13
         1          1       1243         60
         2          1       1278         37
         2          1       1291          0
         2          1       1243         53
         2          2       1228         25
         2          2       1285        103
         2          2       1316         60
         3          2       1228          8
         3          2       1285         25
         3          2        858         43
         3          1       1278         52
         3          1       1394          6
         3          1       1243         31
         4          1       1278         61
         4          1       1394          6
         4          1       1243          3
         4          2       1228         41
         4          2       1285         40
         4          2        858          5
         6          2       1228         20
         6          2       1285        100
         6          2       1408          0
         7          2       1228         15
         7          2       1285         34
         7          2       1408         44
         8          2       1228          0
         8          2       1420         31
         8          2       1340         66
         9          2       1420         19
         9          2       1385         28
         9          2       1340          0
36 rows selected.
SQL> select tt.match_id,
       tt.team_id,
       tt.player_id,
       tt.runs,
       nvl(a.sum_player,0) OCC,
       nvl(b.sum_runs,0) SUM_RUNS
from
tt,
(select a.match_id,a.team_id,a.player_id,a.runs,count(*) sum_player
from tt a,
      (select match_id,player_id
       from   tt
       group by match_id,player_id) b
where a.match_id>b.match_id
and   a.player_id=b.player_id
group by a.match_id,a.team_id,a.player_id,a.runs
) a,
(select a.match_id,a.team_id,a.player_id,a.runs,sum(b.runs) sum_runs
from tt a,
      (select match_id,player_id,runs
       from   tt) b
where a.match_id>b.match_id
and   a.player_id=b.player_id
group by a.match_id,a.team_id,a.player_id,a.runs
) b
where tt.match_id=a.match_id(+)
and tt.team_id=a.team_id(+)
and tt.player_id=a.player_id(+)
and tt.match_id=b.match_id(+)
and tt.team_id=b.team_id(+)
and tt.player_id=b.player_id(+)
  MATCH_ID    TEAM_ID  PLAYER_ID       RUNS        OCC   SUM_RUNS
         1          1       1150         27          0          0
         1          1       1243         60          0          0
         1          1       1278         13          0          0
         1          2       1203         82          0          0
         1          2       1228          8          0          0
         1          2       1316         24          0          0
         2          1       1243         53          1         60
         2          1       1278         37          1         13
         2          1       1291          0          0          0
         2          2       1228         25          1          8
         2          2       1285        103          0          0
         2          2       1316         60          1         24
         3          1       1243         31          2        113
         3          1       1278         52          2         50
         3          1       1394          6          0          0
         3          2        858         43          0          0
         3          2       1228          8          2         33
         3          2       1285         25          1        103
         4          1       1243          3          3        144
         4          1       1278         61          3        102
         4          1       1394          6          1          6
         4          2        858          5          1         43
         4          2       1228         41          3         41
         4          2       1285         40          2        128
         6          2       1228         20          4         82
         6          2       1285        100          3        168
         6          2       1408          0          0          0
         7          2       1228         15          5        102
         7          2       1285         34          4        268
         7          2       1408         44          1          0
         8          2       1228          0          6        117
         8          2       1340         66          0          0
         8          2       1420         31          0          0
         9          2       1340          0          1         66
         9          2       1385         28          0          0
         9          2       1420         19          1         31
36 rows selected.
SQL> Is this do you want ?
Nicolas.

Similar Messages

  • SQL query, function or SP for converting varbinary to image(.jpg format).

    Dear Sir/Mam
    I want SQL query, function or SP which converts binary data to image (.jpg format).
    I m able to convert image (.jpg format) to varbinary. But not able to convert vice versa.
    thanks in advance.

    Binary data is binary data - "image" is only an intrepretation of binary data.  Therefore your question makes little sense in the context of sql server since it does not have any facilities to utilize images.  Since you provide no context, I'm
    guessing that you are trying to retrieve an image stored in the database in a varbinary column and have your application use it as an image.  If so, you should post your question to a forum that is specific to your development environment.  

  • SQ01, SQ01 - Sql Query  Dislplay problem

    Hi
    Need help in SQL Query
    I generated one sql query which has the following output in general .
    Customer      name            description        amount
    asrq1           sharekhan      Amount payed           10
    asrq1           sharekhan      Amount Advance        20
    asrq1           sharekhan      Amount due           30
    but i need the output in the following way
    Customer      name            AMount payed     Amount Advance    Amount Due
    asrq1           sharekhan             10             20                        30
    and iam new this sql query but came to know we can write code ..but iam unable to initiliaze to write
    a peace of code as i dont know what are the select-options defined ..i saw in the include but didnt got it
    % comes prefix of select-options,and iam unable to get he internal table which is displayed in the query .
    can anyone help me in this answers will be awarded points.

    and transaction FBL5N does not work in your company because ... ???

  • SQL query / thread problem!

    I have the following code. when the execute mkethod is called, an instance of TransactionRunner is created. within the run method of TransactionRunner an SQLQuery is executed. I want to return the result set when the query has been executed, how can I do this, at the moment it tries to return the resultSet before the thread has finished. any ideas? I hav tried using a boolean as a flag but it doesn't appear to work.
    public static ResultSet execute(String SQL, boolean rs)
    System.out.println("in execute, dbm") ;
    SQLStatement = SQL ;
    result = rs ;
    complete = false ;
    tr = dbm.new TransactionRunner(SQL) ;
    //SOME FORM OF INDICATION TO THE END OF SQL EXECUTION
    return resultSet ;
    class TransactionRunner implements Runnable
         public ResultSet rs ;
         private Thread queryThread ;
         public String SQLStatement ;
         public TransactionRunner(String SQL)
              SQLStatement = SQL ;
              queryThread = new Thread(this) ;
              queryThread.start() ;
         public void run()
              if (result == true)
                   executeQuery(SQLStatement) ;
                   complete = true;
              else
                   update(SQLStatement) ;
              }

    I am up against the same problem, but I believe that
    you could fire off a progress monitor during the
    thread task and have the thread return the ResultSet.If you're planning to use Swing, then yes, you do need to execute the command in a spawned thread, otherwise your event thread will hang. BUT, spawning a sub-thread from a Swing app is not equivalent to spawning one from a simple console app, because the Swing event thread will keep your process alive. Instead, I would suggest doing something like the following:
    1) In the ActionListener that invokes the query (may be hung off a menu item, or a button, depending on your app):
            public void actionPerformed(ActionEvent actionEvent)
                (new Thread(new MyQuery())).start();
                displayWaitIndication();
            }This method runs in the event thread, and spawns a sub-thread to run the query. It also displays some sort of wait indication, maybe a progress box or a WAIT_CURSOR (I prefer the wait cursor, as you can't accurately display the progress of a server-side operation).
    2) MyQuery implements Runnable:
            public void run()
                List data = // call something to perform DB op here
                SwingUtilities.invokeLater(new Runnable()
                    public void run()
                        mainWindow.refresh(data);
            }This may be a bit confusing, as it leaves a lot of stuff out. I've used "List" as the return from the database function; chances are that you'll actually implement something like MyResultSet. You don't want to use an actual java.sql.ResultSet, because it (may) perform(s) a client-server call to retrieve each row. So, you process the real result-set into a container object (List or whatever) in the sub-thread.
    Then, you pass that container object back to the display window, on the event thread. I've used a variable to access the display window; you may do things differently. The key thing is the use of SwingUtilities.invokeLater(), to perform the actual update on the event thread.
    To summarize:
    1) You initiate the action on the event-thread.
    2) You perform the action in a sub-thread, put the resuls into a container.
    3) You update your display on the event-thread, using SwingUtilities.invokeLater().

  • Pl/SQL Rank() function problem

    Hello everyone....i hv been using Oracle10g for a while now....
    I hv a question which I'm not able to solve now...
    I have this query which shows top 3 employee records based on their joiningdate...the older the joiningdate the higher would be his rank.
    so i run this query....
    select * from(select * rank() over(order by joiningdate desc)daterank from employee) where daterank<=3;
    Following error occurs:
    ERROR at line 1:
    ORA-00923: FROM keyword not found where expected
    How do i solve this problem???
    Edited by: 781207 on Jul 9, 2010 9:42 PM

    Check this query
    1 select empno ,deptno,Hiredate,
    2 dense_rank() OVER (PARTITION BY deptno ORDER BY hiredate) slno
    3* from emp
    SQL> /
    EMPNO DEPTNO HIREDATE SLNO
    7782 10 09-JUN-81 1
    7839 10 17-NOV-81 2
    7934 10 23-JAN-82 3
    7369 20 17-DEC-80 1
    7566 20 02-APR-81 2
    7902 20 03-DEC-81 3
    7788 20 19-APR-87 4
    7876 20 23-MAY-87 5
    7499 30 20-FEB-81 1
    7521 30 22-FEB-81 2
    7698 30 01-MAY-81 3
    EMPNO DEPTNO HIREDATE SLNO
    7844 30 08-SEP-81 4
    7654 30 28-SEP-81 5
    7900 30 03-DEC-81 6
    14 rows selected.
    SQL> ed
    Wrote file afiedt.buf
    1 select empno ,deptno,Hiredate,
    2 dense_rank() OVER (ORDER BY hiredate) slno
    3* from emp
    SQL> /
    EMPNO DEPTNO HIREDATE SLNO
    7369 20 17-DEC-80 1
    7499 30 20-FEB-81 2
    7521 30 22-FEB-81 3
    7566 20 02-APR-81 4
    7698 30 01-MAY-81 5
    7782 10 09-JUN-81 6
    7844 30 08-SEP-81 7
    7654 30 28-SEP-81 8
    7839 10 17-NOV-81 9
    7900 30 03-DEC-81 10
    7902 20 03-DEC-81 10
    EMPNO DEPTNO HIREDATE SLNO
    7934 10 23-JAN-82 11
    7788 20 19-APR-87 12
    7876 20 23-MAY-87 13
    14 rows selected.
    SQL>

  • SQL Query join problem

    Hi,
    I have two tables in my db, the patient table holds details of patients, the contact table holds details of contacts related to the patient.
    patient table
    patientid - primary key - int
    patient name - varchar
    contact table
    contactid - primary key - int
    patientid - foreign key from patient table - int
    incontact - foreign key from paient table to relate contacts - int
    My contact table has the following data:
    contactid patientid incontact
    2              19           21
    2               19          22
    I can retrieve data for the patients that have been in contact with patientid 19, by using the following join:
    SELECT * FROM PATIENT
    LEFT JOIN incontact
    ON incontact.incontact = patient.patientid
    WHERE incontact.patientid = 19
    However, can you please tell me how I can get data from the patients table where the incontact is 21?
    So I can get contacts from patients and patients from contacts?
    Thankyou

    Thanks very much for your replies again.
    Basically, I have a table of patients, and I would like to link them to each other, many to many.
    I populate the incontact table, which stores the original posted patientID, and the new generated patientID. I populate the DB with the code below.
    <cfquery name="update" datasource="staffdirectory">
    SET NOCOUNT ON
    INSERT INTO patient (title,firstname,surname,gender,DOB,telephone,address1,address2,address3,town,postcode
    VALUES ('#title#','#firstname#','#surname#','#gender#',#createodbcdate(createdate(startyear, startmonth, startday))#    ,'#telephone#','#address1#','#address2#','#address3#','#town#','#postcode#
    SELECT @@Identity AS newid   
    SET NOCOUNT OFF
    </cfquery>
          <cfquery name="insert" datasource="staffdirectory">
      INSERT INTO incontact (related,incontact)
    VALUES (#patientid#,#update.newid#)
    </cfquery>
    This works fine and I can get all related patients by usingthe following query:
    SELECT * FROM patient
    LEFT JOIN incontact
    ON patient.patientid  = incontact.related
    WHERE  incontact.incontact = #patientid#
    MY problem occurs when I want to find related patients from the related column, the reverse relationship. I use this seperate query:
    SELECT * FROM patient
    LEFT JOIN incontact
    ON patient.patientid  = incontact.incontact
    WHERE  incontact.related= #patientid#
    Is there a way I can combine both queries, or is there a better way I can achieve the same result?
    Many thanks again

  • Sql query results problem

    Hi All
    When i run the following query am getting the below results:
    SELECT STG_ITS_EMISSIONFACTOR.OPERATION,STG_ITS_EMISSIONFACTOR.SPEED,STG_ITS_EMISSIONFACTOR.VOC,STG_ITS_EMISSIONFACTOR.CO,STG_ITS_EMISSIONFA CTOR.NOX
    from STG_ITS_EMISSIONFACTOR
    results:
    OPERATION SPEED VOC CO NOX
    Operation Speed VOC CO Nox
    Indianapolis 0 4.301 24.651 2.048
    Indianapolis 1 4.301 24.651 2.048
    But when i use the following query am getting the below results :
    SELECT STG_ITS_EMISSIONFACTOR.OPERATION,STG_ITS_EMISSIONFACTOR.SPEED,STG_ITS_EMISSIONFACTOR.VOC,STG_ITS_EMISSIONFACTOR.CO,STG_ITS_EMISSIONFA CTOR.NOX,STG_ITS_SEGMENTCATEGORY_LUT.RTDIRNTYMEAS,STG_ITS_SEGMENTCATEGORY_LUT.SEGMENT,STG_ITS_SEGMENTMULTIPLIER.MULTIPLIER
    from STG_ITS_EMISSIONFACTOR,STG_ITS_SEGMENTCATEGORY_LUT,STG_ITS_SEGMENTMULTIPLIER
    am getting the results as :
    OPERATION SPEED VOC CO NOX RTDIRNTYMEAS SEGMENT MULTIPLIER
    Operation Speed VOC CO Nox 69 s m 15.7 23 4.69
    Operation Speed VOC CO Nox 465 e m 25.1 35 4.69
    Operation Speed VOC CO Nox 70 e m 84.7 47 4.69

    sorry the actual problem was
    Hi all
    When i use the UNION i'm getting strange results:
    SELECT OPERATION,SPEED,VOC,CO,NOX from STG_ITS_EMISSIONFACTOR
    union
    select RTDIRNTYMEAS,NULL,NULL,NULL,NULL from STG_ITS_SEGMENTCATEGORY_LUT
    RESULTS:
    OPERATION     SPEED     VOC     CO     NOX
    31 n m 126.3                    
    31 n m 127.3                    
    31 n m 131.1                    
    31 n m 132.3                    
    31 n m 134.7                    
    31 s m 125.5                    
    31 s m 129.5                    
    Indianapolis     40     0.63     8.935     1.191
    Indianapolis     43     0.6186     8.548     1.2162
    Indianapolis     44     0.6148     8.419     1.2246
    Indianapolis     47     0.6042     8.8396     1.2578
    Indianapolis     48     0.6008     9.1144     1.2702
    Indianapolis     49     0.5974     9.3892     1.2826
    Please any help is greatly appreciated.
    Thanks
    Edited by: thinkingeye on Apr 3, 2009 2:45 PM

  • Sql query efficiency problem.

    Hello,
    I have a table - Users: | id | name | manager_id |
    The manager_id references the User.id,
    I need to find an employee by an id or name and this employee has to be a manager to someone else.
    Creating a sub-select that checks if employee's id is present within manager_id column takes a bit of time, is there a way to, for example, inner join the table to it self leaving only the rows that are managers.

    Thank you both for your quick answers.
    @ Rene Argento
    The self-join is something I am interested in, but I don't exactly know how to write it so that it returns the same result set as the sub-select query you wrote.
    @ Frank Kulash
    Thanks for the query, but is there a possibility to re-write Rene's query to a JOIN query which excludes all the employees who are not managers to someone.
    Or maybe there is another way to create the needed query which would be faster than using sub-select for each user ?
    Thanks in advance.
    Edited by: 909522 on 2012.22.1 10:09
    Edited by: 909522 on 2012.22.1 10:10

  • SQL QUERY COUNT PROBLEM

    Employees:
    Employee_ID Name
    01 Hansen, Ola
    02 Svendson, Tove
    03 Svendson, Stephen
    04 Pettersen, Kari
    Orders:
    Prod_ID Product Employee_ID
    234 Printer 01
    657 Table 03
    865 Chair 03
    SELECT Employees.Name, Orders.Product
    FROM Employees, Orders
    WHERE Employees.Employee_ID=Orders.Employee_ID
    My question is :how to take the count of particular field from above query from the second table.

    Please don't re-post or cross-post.
    SELECT employee.name, COUNT(*)
    FROM employee, product
    WHERE employee.employee_id = product.employee_id
    GROUP BY employee.name
    - Saish

  • OBIEE SQL Query formate problem

    Hai All,
    i am tring to see viewlog in obiee it is givinn the following formate.
    WITH
    SAWITH0 AS (select sum(T338777.CST) as c1,
    sum(T338777.FINAL_INVOICE_AMT) as c2,
    T66199.X_DISP_FSCL_YEAR as c3,
    T66199.FSCL_MONTH as c4,
    substr(T66199.MONTH_NAME , 1, 3) as c5,
    T37817.NAME as c6,
    T101991.NAME as c7,
    T66199.FSCL_YEAR as c8,
    T101991.ROW_WID as c9
    from
    W_INT_ORG_D T37817,
    W_ORG_D T101991 /* Division (W_ORG_D) */ ,
    W_MONTH_D T66199 /* Generic Month (W_MONTH_D) */ ,
    WC_INVC_SPARES_PO_A T338777 /* Spare PO(WC_INVC_SPARES_PO_A) */
    where ( T37817.ROW_WID = T338777.ORG_WID and T66199.ROW_WID = T338777.MONTH_WID and T66199.X_DISP_FSCL_YEAR = '2010-11' and T101991.ROW_WID = T338777.DIVN_WID and T101991.DIVN_FLG = 'Y' )
    group by T37817.NAME, T66199.FSCL_MONTH, T66199.FSCL_YEAR, T66199.X_DISP_FSCL_YEAR, T101991.NAME, T101991.ROW_WID, substr(T66199.MONTH_NAME , 1, 3))
    I need the  following formate. what should i do?
    select sum(T338777.CST) as c1,
    sum(T338777.FINAL_INVOICE_AMT) as c2,
    T66199.X_DISP_FSCL_YEAR as c3,
    T66199.FSCL_MONTH as c4,
    substr(T66199.MONTH_NAME , 1, 3) as c5,
    T37817.NAME as c6,
    T101991.NAME as c7,
    T66199.FSCL_YEAR as c8,
    T101991.ROW_WID as c9
    from
    W_INT_ORG_D T37817,
    W_ORG_D T101991 /* Division (W_ORG_D) */ ,
    W_MONTH_D T66199 /* Generic Month (W_MONTH_D) */ ,
    WC_INVC_SPARES_PO_A T338777 /* Spare PO(WC_INVC_SPARES_PO_A) */
    where ( T37817.ROW_WID = T338777.ORG_WID and T66199.ROW_WID = T338777.MONTH_WID and T66199.X_DISP_FSCL_YEAR = '2010-11' and T101991.ROW_WID = T338777.DIVN_WID and T101991.DIVN_FLG = 'Y' )
    group by T37817.NAME, T66199.FSCL_MONTH, T66199.FSCL_YEAR, T66199.X_DISP_FSCL_YEAR, T101991.NAME, T101991.ROW_WID, substr(T66199.MONTH_NAME , 1, 3))
    Regards,
    Ram

    Hi,
    You messed up with database features in OBIEE rpd. Check the below link
    http://gerardnico.com/wiki/dat/obiee/vertical_fragmentation_sql
    Regards,
    Sandeep

  • Using Package to produce pl/sql function body returning sql query Report

    I have existing code that we want to use in building reports in APEX. We are needing to modify it slightly to handle some new requirements, but would like to use them in reports based upon SQL query (pl/sql function body returning sql query) functionality.
    Any suggestions as how to call these in an APEX report region?
    Thank you,
    Tony Miller
    UTMB/EHN

    Hi Tony-
    I am also v new to Apex and you may have answered a question I was in search of. I, however, now have a couple more. First a bit of background-- Like in your situation, my college has a lot of existing code (400 +) that we need to get into Apex. The majority of this canned code contains one/both: 1) many lines, sometimes containing multiple select statements 2) imbedded create table & view statements (temp user owned). Up until reading your post, I was unable to figure out an easy way of getting this existing code into the product. Thanks. Now the questions, do you know how I would go about dealing with the create tables/views. I've read some posts on this forum which suggest temporary tables being unstable in this environment. Also, do you know if there's a size limitation when passing sql code via a function?
    As you may/may not be able to tell, I'm a bit lost right now... so any info you can provide would be appreciated. Thanks.
    Don

  • Reagrding some typical sql query in oracle8i

    hi all,
    i am facing a problem in sql query,My problem is like that
    table emp data like that :
    emp_id sal
    10 1000
    20 2000
    30 3000
    and i want to show data as follows-
    emp_id sal
    10 1000
    20 3000
    30 6000
    just show the cumulative total of salary column.
    plz its urgent.
    ok
    bye

    SQL> create table t (emp_id number
      2  ,sal number
      3  );
    Table created.
    SQL> insert into t values (10, 1000);
    1 row created.
    SQL> insert into t values (20, 2000);
    1 row created.
    SQL> insert into t values (30, 3000);
    1 row created.
    SQL>
    SQL>
    SQL> select emp_id
      2       , sal
      3       , Sum (sal) over (order by emp_id) sum_sal
      4    from t
      5  /
        EMP_ID        SAL    SUM_SAL
            10       1000       1000
            20       2000       3000
            30       3000       6000

  • SQL query to find all suites that are associated with automation

    I trying to incorporate CodeUI tests into a Release Mangement deployment template ... As a developer, I want to be able to specify a sub-tree of a test plan & only execute those test suites that are associated with automation.  Is there a way to
    extract all automated workitems and associated them with their respective test suites?
    Any assistance would be greatly appreciated!

    John,
    I've partially resolved the issue of executing a sub-set of suites with the following powershell implementation:
    1. Extract "potential" suite paths from a XML configuration file:
    <?xml version="1.0"?>
    <Configurations>
    <Properties>
    <Property key="DEFAULT" value="SuitePaths" />
    <Property key="DatabaseServer" value="MYDBSERVER" />
    <Property key="DatabaseInstance" value="Default" />
    <Property key="DatabaseName" value="TFS_DefaultCollection" />
    <Property key="ConfigurationName" value="US - Windows 7 and IE 10" />
    </Properties>
    <Notifications>
    <Notification key="0" value="[email protected]" />
    </Notifications>
    <SuitePaths>
    <SuitePath key="0" value="MyProject\WebProduct\Student\Features\Login" />
    <SuitePath key="1" value="MyProject\WebProduct\Student\Features\Logout" />
    </SuitePaths>
    <AreaPaths>
    <AreaPath key="0" value="MyProject\WebProduct\Student\Features\Login" />
    </AreaPaths>
    </Configurations>
    2. Extract record set of suites from TFS via SQL query:
    # FUNCTION: Retrieve-SuitePaths
    # Parameters:
    # (1.) LogFile -- Name of log file (e.g., C:\Temp or C:\Temp\DEPLOY_DatabaseServer_WebCMS2_DF06_20131031.6.log)
    # (2.) Connection -- Database connection
    # (3.) Paths -- Hash table of suite paths
    Function Retrieve-SuitePaths
    param
    [Parameter(Mandatory=$True)][String]$LogFile,
    [Parameter(Mandatory=$True)]$Connection,
    [Parameter(Mandatory=$True)]$Paths
    Write-Output '--------------------------------------------------------------------------------' | Out-File -FilePath $LogFile -Append
    Write-Output "Retrieve suite(s): " | Out-File -FilePath $LogFile -Append
    Write-Output '--------------------------------------------------------------------------------' | Out-File -FilePath $LogFile -Append
    $SuitePaths = "("
    $Counter = 0
    foreach ($Key in $Paths.Keys)
    if ($Counter -gt 0)
    $SuitePaths = $SuitePaths + ", "
    $SuitePaths = $SuitePaths + "'" + $Paths.Get_Item($Key) + "'"
    $Counter += 1
    $SuitePaths = $SuitePaths + ")"
    # --DEBUG ONLY--> Write-Output "Paths: $SuitePaths" | Out-File -FilePath $LogFile -Append
    $Command = New-Object System.Data.SqlClient.SqlCommand
    $SQLStatement = "
    WITH
    cte_SuiteChildren
    AS
    -- Anchor definition to pull all certify modes
    SELECT
    S.[SuiteId],
    S.[ProjectId],
    PJ.ProjectName,
    S.[PlanId],
    P.[Name] AS PlanName,
    S.[ParentSuiteId],
    S.[SuitePath],
    CONVERT(NVARCHAR(256), NULL) AS ParentTitle,
    S.[Title],
    0 AS RecurseLevel
    FROM
    [dbo].[tbl_Suite] AS S
    INNER JOIN [dbo].[tbl_Plan] AS P ON S.PlanID = P.PlanID
    INNER JOIN [dbo].[tbl_Project] AS PJ ON S.ProjectID = PJ.ProjectID
    WHERE
    S.ParentSuiteID = 0
    UNION ALL
    -- Recursive member to pull details of certify sessions
    SELECT
    S.[SuiteId],
    S.[ProjectId],
    PJ.ProjectName,
    S.[PlanId],
    P.[Name] AS PlanName,
    S.[ParentSuiteId],
    S.[SuitePath],
    PS.[Title] AS ParentTitle,
    S.[Title],
    SC.[RecurseLevel] + 1 AS RecurseLevel
    FROM
    [dbo].[tbl_Suite] AS S
    INNER JOIN cte_SuiteChildren AS SC on SC.SuiteID = S.ParentSuiteID
    INNER JOIN [dbo].[tbl_Suite] AS PS ON SC.SuiteId = PS.SuiteId
    INNER JOIN [dbo].[tbl_Plan] AS P ON S.PlanID = P.PlanID
    INNER JOIN [dbo].[tbl_Project] AS PJ ON S.ProjectID = PJ.ProjectID
    cte_SuiteLevel_0
    AS
    SELECT
    SC.[ProjectId],
    SC.[PlanId],
    SC.[SuiteId],
    SC.[ProjectName],
    SC.[PlanName],
    SC.[Title],
    SC.[ProjectName] + '\' + SC.[PlanName] AS Path,
    SC.[RecurseLevel]
    FROM
    cte_SuiteChildren AS SC
    WHERE
    SC.[RecurseLevel] = 0
    cte_SuiteLevel_1
    AS
    SELECT
    SC.[ProjectId],
    SC.[PlanId],
    SC.[ParentSuiteId],
    SC.[SuiteId],
    SC.[ProjectName],
    SC.[PlanName],
    SC.[Title],
    SC.[RecurseLevel]
    FROM
    cte_SuiteChildren AS SC
    WHERE
    SC.[RecurseLevel] = 1
    cte_SuiteLevel_2
    AS
    SELECT
    SC.[ProjectId],
    SC.[PlanId],
    SC.[ParentSuiteId],
    SC.[SuiteId],
    SC.[ProjectName],
    SC.[PlanName],
    SC.[Title],
    SC.[RecurseLevel]
    FROM
    cte_SuiteChildren AS SC
    WHERE
    SC.[RecurseLevel] = 2
    cte_SuiteLevel_3
    AS
    SELECT
    SC.[ProjectId],
    SC.[PlanId],
    SC.[ParentSuiteId],
    SC.[SuiteId],
    SC.[ProjectName],
    SC.[PlanName],
    SC.[Title],
    SC.[RecurseLevel]
    FROM
    cte_SuiteChildren AS SC
    WHERE
    SC.[RecurseLevel] = 3
    cte_SuiteLevel_4
    AS
    SELECT
    SC.[ProjectId],
    SC.[PlanId],
    SC.[ParentSuiteId],
    SC.[SuiteId],
    SC.[ProjectName],
    SC.[PlanName],
    SC.[Title],
    SC.[RecurseLevel]
    FROM
    cte_SuiteChildren AS SC
    WHERE
    SC.[RecurseLevel] = 4
    cte_SuiteLevel_5
    AS
    SELECT
    SC.[ProjectId],
    SC.[PlanId],
    SC.[ParentSuiteId],
    SC.[SuiteId],
    SC.[ProjectName],
    SC.[PlanName],
    SC.[Title],
    SC.[RecurseLevel]
    FROM
    cte_SuiteChildren AS SC
    WHERE
    SC.[RecurseLevel] = 5
    cte_SuiteLevel_6
    AS
    SELECT
    SC.[ProjectId],
    SC.[PlanId],
    SC.[ParentSuiteId],
    SC.[SuiteId],
    SC.[ProjectName],
    SC.[PlanName],
    SC.[Title],
    SC.[RecurseLevel]
    FROM
    cte_SuiteChildren AS SC
    WHERE
    SC.[RecurseLevel] = 6
    cte_SuiteLevel_7
    AS
    SELECT
    SC.[ProjectId],
    SC.[PlanId],
    SC.[ParentSuiteId],
    SC.[SuiteId],
    SC.[ProjectName],
    SC.[PlanName],
    SC.[Title],
    SC.[RecurseLevel]
    FROM
    cte_SuiteChildren AS SC
    WHERE
    SC.[RecurseLevel] = 7
    cte_SuiteLevel_8
    AS
    SELECT
    SC.[ProjectId],
    SC.[PlanId],
    SC.[ParentSuiteId],
    SC.[SuiteId],
    SC.[ProjectName],
    SC.[PlanName],
    SC.[Title],
    SC.[RecurseLevel]
    FROM
    cte_SuiteChildren AS SC
    WHERE
    SC.[RecurseLevel] = 8
    cte_SuiteLevel_9
    AS
    SELECT
    SC.[ProjectId],
    SC.[PlanId],
    SC.[ParentSuiteId],
    SC.[SuiteId],
    SC.[ProjectName],
    SC.[PlanName],
    SC.[Title],
    SC.[RecurseLevel]
    FROM
    cte_SuiteChildren AS SC
    WHERE
    SC.[RecurseLevel] = 9
    cte_SuiteLevel_10
    AS
    SELECT
    SC.[ProjectId],
    SC.[PlanId],
    SC.[ParentSuiteId],
    SC.[SuiteId],
    SC.[ProjectName],
    SC.[PlanName],
    SC.[Title],
    SC.[RecurseLevel]
    FROM
    cte_SuiteChildren AS SC
    WHERE
    SC.[RecurseLevel] = 10
    cte_Suites
    AS
    SELECT
    SL0.[ProjectId],
    SL0.[PlanId],
    CASE
    WHEN SL2.ParentSuiteId IS NULL
    THEN SL1.ParentSuiteId
    ELSE CASE
    WHEN SL3.ParentSuiteId IS NULL
    THEN SL2.ParentSuiteId
    ELSE CASE
    WHEN SL4.ParentSuiteId IS NULL
    THEN SL3.ParentSuiteId
    ELSE CASE
    WHEN SL5.ParentSuiteId IS NULL
    THEN SL4.ParentSuiteId
    ELSE CASE
    WHEN SL6.ParentSuiteId IS NULL
    THEN SL5.ParentSuiteId
    ELSE CASE
    WHEN SL7.ParentSuiteId IS NULL
    THEN SL6.ParentSuiteId
    ELSE CASE
    WHEN SL8.ParentSuiteId IS NULL
    THEN SL7.ParentSuiteId
    ELSE CASE
    WHEN SL9.ParentSuiteId IS NULL
    THEN SL8.ParentSuiteId
    ELSE CASE
    WHEN SL10.ParentSuiteId IS NULL
    THEN SL9.ParentSuiteId
    ELSE SL10.ParentSuiteId
    END
    END
    END
    END
    END
    END
    END
    END
    END AS [ParentSuiteId],
    CASE
    WHEN SL2.SuiteId IS NULL
    THEN SL1.SuiteId
    ELSE CASE
    WHEN SL3.SuiteId IS NULL
    THEN SL2.SuiteId
    ELSE CASE
    WHEN SL4.SuiteId IS NULL
    THEN SL3.SuiteId
    ELSE CASE
    WHEN SL5.SuiteId IS NULL
    THEN SL4.SuiteId
    ELSE CASE
    WHEN SL6.SuiteId IS NULL
    THEN SL5.SuiteId
    ELSE CASE
    WHEN SL7.SuiteId IS NULL
    THEN SL6.SuiteId
    ELSE CASE
    WHEN SL8.SuiteId IS NULL
    THEN SL7.SuiteId
    ELSE CASE
    WHEN SL9.SuiteId IS NULL
    THEN SL8.SuiteId
    ELSE CASE
    WHEN SL10.SuiteId IS NULL
    THEN SL9.SuiteId
    ELSE SL10.SuiteId
    END
    END
    END
    END
    END
    END
    END
    END
    END AS [SuiteId],
    SL0.ProjectName,
    SL0.PlanName,
    --SL0.Path,
    --SL1.[Title],
    CASE
    WHEN SL2.Title IS NULL
    THEN SL0.Path + '\' + SL1.Title
    ELSE CASE
    WHEN SL3.Title IS NULL
    THEN SL0.Path + '\' + SL1.Title + '\' + SL2.Title
    ELSE CASE
    WHEN SL4.Title IS NULL
    THEN SL0.Path + '\' + SL1.Title + '\' + SL2.Title + '\' + SL3.Title
    ELSE CASE
    WHEN SL5.Title IS NULL
    THEN SL0.Path + '\' + SL1.Title + '\' + SL2.Title + '\' + SL3.Title + '\' + SL4.Title
    ELSE CASE
    WHEN SL6.Title IS NULL
    THEN SL0.Path + '\' + SL1.Title + '\' + SL2.Title + '\' + SL3.Title + '\' + SL4.Title + '\' + SL5.Title
    ELSE CASE
    WHEN SL7.Title IS NULL
    THEN SL0.Path + '\' + SL1.Title + '\' + SL2.Title + '\' + SL3.Title + '\' + SL4.Title + '\' + SL5.Title + '\' + SL6.Title
    ELSE CASE
    WHEN SL8.Title IS NULL
    THEN SL0.Path + '\' + SL1.Title + '\' + SL2.Title + '\' + SL3.Title + '\' + SL4.Title + '\' + SL5.Title + '\' + SL6.Title + '\' + SL7.Title
    ELSE CASE
    WHEN SL9.Title IS NULL
    THEN SL0.Path + '\' + SL1.Title + '\' + SL2.Title + '\' + SL3.Title + '\' + SL4.Title + '\' + SL5.Title + '\' + SL6.Title + '\' + SL7.Title + '\' + SL8.Title
    ELSE CASE
    WHEN SL10.Title IS NULL
    THEN SL0.Path + '\' + SL1.Title + '\' + SL2.Title + '\' + SL3.Title + '\' + SL4.Title + '\' + SL5.Title + '\' + SL6.Title + '\' + SL7.Title + '\' + SL8.Title + '\' + SL9.Title
    ELSE SL0.Path + '\' + SL1.Title + '\' + SL2.Title + '\' + SL3.Title + '\' + SL4.Title + '\' + SL5.Title + '\' + SL6.Title + '\' + SL7.Title + '\' + SL8.Title + '\' + SL9.Title + '\' + SL10.Title
    END
    END
    END
    END
    END
    END
    END
    END
    END AS Path,
    CASE
    WHEN SL2.RecurseLevel IS NULL
    THEN SL1.RecurseLevel
    ELSE CASE
    WHEN SL3.RecurseLevel IS NULL
    THEN SL2.RecurseLevel
    ELSE CASE
    WHEN SL4.RecurseLevel IS NULL
    THEN SL3.RecurseLevel
    ELSE CASE
    WHEN SL5.RecurseLevel IS NULL
    THEN SL4.RecurseLevel
    ELSE CASE
    WHEN SL6.RecurseLevel IS NULL
    THEN SL5.RecurseLevel
    ELSE CASE
    WHEN SL7.RecurseLevel IS NULL
    THEN SL6.RecurseLevel
    ELSE CASE
    WHEN SL8.RecurseLevel IS NULL
    THEN SL7.RecurseLevel
    ELSE CASE
    WHEN SL9.RecurseLevel IS NULL
    THEN SL8.RecurseLevel
    ELSE CASE
    WHEN SL10.RecurseLevel IS NULL
    THEN SL9.RecurseLevel
    ELSE SL10.RecurseLevel
    END
    END
    END
    END
    END
    END
    END
    END
    END AS RecurseLevel
    FROM
    cte_SuiteLevel_0 AS SL0
    LEFT OUTER JOIN cte_SuiteLevel_1 AS SL1 ON SL1.ParentSuiteId = SL0.SuiteId
    LEFT OUTER JOIN cte_SuiteLevel_2 AS SL2 ON SL2.ParentSuiteId = SL1.SuiteId
    LEFT OUTER JOIN cte_SuiteLevel_3 AS SL3 ON SL3.ParentSuiteId = SL2.SuiteId
    LEFT OUTER JOIN cte_SuiteLevel_4 AS SL4 ON SL4.ParentSuiteId = SL3.SuiteId
    LEFT OUTER JOIN cte_SuiteLevel_5 AS SL5 ON SL5.ParentSuiteId = SL4.SuiteId
    LEFT OUTER JOIN cte_SuiteLevel_6 AS SL6 ON SL6.ParentSuiteId = SL5.SuiteId
    LEFT OUTER JOIN cte_SuiteLevel_7 AS SL7 ON SL7.ParentSuiteId = SL6.SuiteId
    LEFT OUTER JOIN cte_SuiteLevel_8 AS SL8 ON SL8.ParentSuiteId = SL7.SuiteId
    LEFT OUTER JOIN cte_SuiteLevel_9 AS SL9 ON SL9.ParentSuiteId = SL8.SuiteId
    LEFT OUTER JOIN cte_SuiteLevel_10 AS SL10 ON SL10.ParentSuiteId = SL9.SuiteId
    SELECT
    SS.[ProjectId],
    SS.[PlanId],
    SS.[ParentSuiteId],
    SS.[SuiteId],
    SS.[ProjectName],
    SS.[PlanName],
    SS.[Path],
    SS.[RecurseLevel]
    FROM
    SELECT DISTINCT
    S.[ProjectId],
    S.[PlanId],
    S.[ParentSuiteId],
    S.[SuiteId],
    S.[ProjectName],
    S.[PlanName],
    S.[Path],
    S.[RecurseLevel]
    FROM
    cte_Suites AS S
    WHERE
    S.[RecurseLevel] IS NOT NULL
    AND S.[Path] IN $($SuitePaths)
    ) AS SS
    ORDER BY
    SS.[Path]
    $Command.CommandText = $SQLStatement
    $Command.Connection = $Connection
    $Command.CommandTimeout = 240
    $DataAdapter = New-Object System.Data.SqlClient.SqlDataAdapter
    $DataAdapter.SelectCommand = $Command
    $DataSet = New-Object System.Data.DataSet
    $DataAdapter.Fill($DataSet) | Out-Null
    Write-Output "$SQLStatement" | Out-File -FilePath $LogFile -Append
    # --DEBUG ONLY--> $DataSet.Tables[0]
    return $DataSet
    3. Execute every suite in the record set via TCM
    $DataSet = ( Retrieve-SuitePaths -LogFile:$LogFile -Connection:$Connection -Path:$Paths)
    # --DEBUG ONLY--> $DataSet.Tables[0].Rows.Count
    # --DEBUG ONLY--> $DataSet.Tables[0]
    # Determine whether or not any test suites were retrieved from TFS....
    if ( $DataSet.Tables[0].Rows.Count -gt 0 )
    $ListTestRunID = $null
    $SumFailed = 0
    $SumInconclusive = 0
    foreach ($Row in $DataSet.Tables[0].Rows)
    # Set project, plan & suite variables....
    [Int16]$ProjectID = $Row.Item('ProjectId')
    [Int16]$PlanID = $Row.Item('PlanId')
    [Int16]$ParentSuiteID = $Row.Item('ParentSuiteId')
    [Int16]$SuiteID = $Row.Item('SuiteId')
    $ProjectName = $Row.Item('ProjectName')
    $PlanName = $Row.Item('PlanName')
    $Path = $Row.Item('Path')
    $RecurseLevel = $Row.Item('RecurseLevel')
    # Set local build path variable....
    switch -wildcard ($Path)
    "*WebCMS*\Administration\*"
    $CUITBuildPath = $CUITPathUNC + '\WebCMS\Administration'
    "*WebCMS*\Instructor\*"
    $CUITBuildPath = $CUITPathUNC + '\WebCMS\Instructor'
    "*WebCMS*\Student\*"
    $CUITBuildPath = $CUITPathUNC + '\WebCMS\Student'
    "*WebProduct*\Instructor\*"
    $CUITBuildPath = $CUITPathUNC + '\WebProduct\Instructor'
    "*WebProduct*\Student\*"
    $CUITBuildPath = $CUITPathUNC + '\WebProduct\Student'
    default
    $CUITBuildPath = $CUITPathUNC
    Write-Output '--------------------------------------------------------------------------------' | Out-File -FilePath $LogFile -Append
    Write-Output 'Test Suite:' | Out-File -FilePath $LogFile -Append
    Write-Output '--------------------------------------------------------------------------------' | Out-File -FilePath $LogFile -Append
    Write-Output " ID:" | Out-File -FilePath $LogFile -Append
    Write-Output " Project: $ProjectID" | Out-File -FilePath $LogFile -Append
    Write-Output " Plan: $PlanID" | Out-File -FilePath $LogFile -Append
    Write-Output " Parent Suite: $ParentSuiteID" | Out-File -FilePath $LogFile -Append
    Write-Output " Suite: $SuiteID" | Out-File -FilePath $LogFile -Append
    Write-Output " Config: $ConfigurationID" | Out-File -FilePath $LogFile -Append
    Write-Output " Name:" | Out-File -FilePath $LogFile -Append
    Write-Output " Project: $ProjectName" | Out-File -FilePath $LogFile -Append
    Write-Output " Plan: $PlanName" | Out-File -FilePath $LogFile -Append
    Write-Output " Config: $ConfigurationName" | Out-File -FilePath $LogFile -Append
    Write-Output " Path:" | Out-File -FilePath $LogFile -Append
    Write-Output " Suite: $Path" | Out-File -FilePath $LogFile -Append
    Write-Output " Build: $CUITBuildPath" | Out-File -FilePath $LogFile -Append
    # --DEBUG ONLY--> Write-Output " Recursion: $RecurseLevel" | Out-File -FilePath $LogFile -Append
    Write-Output '--------------------------------------------------------------------------------' | Out-File -FilePath $LogFile -Append
    # Set TCM arguements....
    $ArguementPlanID = "/planid:$PlanID"
    $ArguementTitle = "/title:$Title - $Path (SuiteID: $SuiteID)"
    $ArguementSuiteID = "/suiteid:$SuiteID"
    $ArguementConfigurationID = "/configid:$ConfigurationID"
    $ArguementTFSCollection = "/collection:$TFSCollection"
    $ArguementTeamProject = "/teamproject:$TFSTeamProject"
    if(![string]::IsNullOrEmpty($CUITBuildPath))
    $ArguementBuildDirectory = "/builddir:$CUITBuildPath"
    $ArguementBuild = ""
    $ArguementBuildDefinition = ""
    else
    $ArguementBuildDirectory = ""
    $ArguementBuild = "/build:$TFSBuild"
    $ArguementBuildDefinition = "/builddefinition:$BuildDefinition"
    $ArguementTestEnvironment = "/testenvironment:$WebServer"
    $ArguementSettingsName = ""
    if(![string]::IsNullOrEmpty($SettingsName))
    $ArguementSettingsName = "/settingsname:$SettingsName"
    # Create test run....
    Write-Host "$TCMEXE 'run' '/create' $ArguementTitle $ArguementPlanID $ArguementSuiteID $ArguementConfigurationID $ArguementTFSCollection $ArguementTeamProject $ArguementBuild $ArguementBuildDefinition $ArguementBuildDirectory $ArguementTestEnvironment $ArguementSettingsName"
    Write-Output " $TCMEXE 'run' '/create' $ArguementTitle $ArguementPlanID $ArguementSuiteID $ArguementConfigurationID $ArguementTFSCollection $ArguementTeamProject $ArguementBuild $ArguementBuildDefinition $ArguementBuildDirectory $ArguementTestEnvironment $ArguementSettingsName" | Out-File -FilePath $LogFile -Append
    try
    $TestRunID = & $TCMEXE 'run' '/create' $ArguementTitle $ArguementPlanID $ArguementSuiteID $ArguementConfigurationID $ArguementTeamProject $ArguementTFSCollection $ArguementBuild $ArguementBuildDefinition $ArguementBuildDirectory $ArguementTestEnvironment $ArguementSettingsName
    catch
    $ExitMessage = $_Exception.Message
    # --DEBUG ONLY--> Write-Output "TestRunID: $TestRunID" | Out-File -FilePath $LogFile -Append
    if ($TestRunID -match '.+\:\s(?<TestRunID>\d+)\.')
    # The test run ID is identified as a property in the match collection so we can access it directly by using the group name from the regular expression (i.e. TestRunID).
    $TestRunID = $matches.TestRunID
    $ArguementID = "/id:$TestRunID"
    $TestRunResultsFile = $TempDirectory + "\TestRunResults$TestRunID.trx"
    $ArguementQueryText = "/querytext:SELECT * FROM TestRun WHERE TestRunID=$TestRunID"
    $ArguementResultsFile = "/resultsfile:""$TestRunResultsFile"""
    Write-Host " Waiting for test run to complete ..."
    Write-Host $TCMEXE 'run' '/list' $ArguementTeamProject $ArguementTFSCollection $ArguementQueryText
    Write-Output " $TCMEXE 'run' '/list' $ArguementTeamProject $ArguementTFSCollection $ArguementQueryText" | Out-File -FilePath $LogFile -Append
    $WaitingForTestRunCompletion = $true
    $WaitCount= 0
    while ($WaitingForTestRunCompletion)
    $WaitCount = $WaitCount + 1
    Write-Output " Waiting ($WaitCount)...." | Out-File -FilePath $LogFile -Append
    Start-Sleep -s $TestRunWaitDelay
    $TestRunStatus = & $TCMEXE 'run' '/list' $ArguementTeamProject $ArguementTFSCollection $ArguementQueryText
    $TestRunStatus
    if ($TestRunStatus.Count -lt 3 -or ($TestRunStatus.Count -gt 2 -and $TestRunStatus.GetValue(2) -match '.+(?<DateCompleted>\d+[/]\d+[/]\d+)'))
    $WaitingForTestRunCompletion = $false
    Write-Host "Evaluating test run $TestRunID results..."
    # Take small pause(s) since the results might not be published yet....
    Start-Sleep -s $TestRunWaitDelay
    # Export results....
    Write-Host $TCMEXE 'run' '/export' $ArguementID $ArguementTeamProject $ArguementTFSCollection $ArguementResultsFile
    Write-Output " $TCMEXE 'run' '/export' $ArguementID $ArguementTeamProject $ArguementTFSCollection $ArguementResultsFile" | Out-File -FilePath $LogFile -Append
    $WaitingForTestRunExport = $true
    $WaitCount= 0
    while ($WaitingForTestRunExport -and $WaitCount -lt 5)
    $WaitCount = $WaitCount + 1
    Write-Output " Waiting ($WaitCount)...." | Out-File -FilePath $LogFile -Append
    $ExportResult = & $TCMEXE 'run' '/export' $ArguementID $ArguementResultsFile $ArguementTFSCollection $ArguementTeamProject
    if ([System.IO.File]::Exists($TestRunResultsFile))
    $WaitingForTestRunExport = $false
    if ([System.IO.File]::Exists($TestRunResultsFile))
    # Load the XML document contents.
    [xml]$TestResultsXML = Get-Content "$TestRunResultsFile"
    # Extract the results of the test run.
    $TotalTests = $TestResultsXML.TestRun.ResultSummary.Counters.total
    $PassedTests = $TestResultsXML.TestRun.ResultSummary.Counters.passed
    $FailedTests = $TestResultsXML.TestRun.ResultSummary.Counters.failed
    $InconclusiveTests = $TestResultsXML.TestRun.ResultSummary.Counters.inconclusive
    # Output the results of the test run.
    Write-Host "========== Test: $TotalTests tests ran, $PassedTests succeeded, $FailedTests failed, $InconclusiveTests inconclusive =========="
    Write-Output "--------------------------------------------------------------------------------" | Out-File -FilePath $LogFile -Append
    Write-Output "Summary:" | Out-File -FilePath $LogFile -Append
    Write-Output "--------------------------------------------------------------------------------" | Out-File -FilePath $LogFile -Append
    Write-Output " Total: $TotalTests" | Out-File -FilePath $LogFile -Append
    Write-Output " Passed: $PassedTests" | Out-File -FilePath $LogFile -Append
    Write-Output " Failed: $FailedTests" | Out-File -FilePath $LogFile -Append
    Write-Output " Inconclusive: $InconclusiveTests" | Out-File -FilePath $LogFile -Append
    $SumFailed += $FailedTests
    $SumInconclusive += $InconclusiveTests
    # Remove the test run results file.
    [System.IO.File]::Delete($TestRunResultsFile) | Out-Null
    # Add "current" TestRunID to the list of TestRunID(s)....
    if ($ListTestRunID -ne $null)
    $ListTestRunID = $ListTestRunID + ', '
    $ListTestRunID = $ListTestRunID + $TestRunID
    # Next test suite....
    4. Extract record set of test runs  from TFS via SQL query:
    # FUNCTION: Retrieve-TestRuns
    # Parameters:
    # (1.) LogFile -- Name of log file (e.g., C:\Temp or C:\Temp\DEPLOY_DatabaseServer_WebCMS2_DF06_20131031.6.log)
    # (2.) Connection -- Database connection
    # (3.) ListTestRunID -- List of test run identifiers
    Function Retrieve-TestRuns
    param
    [Parameter(Mandatory=$True)][String]$LogFile,
    [Parameter(Mandatory=$True)]$Connection,
    [Parameter(Mandatory=$True)][String]$ListTestRunID
    Write-Output '--------------------------------------------------------------------------------' | Out-File -FilePath $LogFile -Append
    Write-Output "Retrieve test run(s): " | Out-File -FilePath $LogFile -Append
    Write-Output '--------------------------------------------------------------------------------' | Out-File -FilePath $LogFile -Append
    $TestRuns = '(' + $ListTestRunID + ')'
    $Command = New-Object System.Data.SqlClient.SqlCommand
    $SQLStatement = "
    WITH
    cte_State
    AS
    SELECT 0 AS [StateID], 'Unspecified' AS [StateName]
    UNION ALL
    SELECT 1 AS [OutcomeId], 'To Be Determined (1)' AS [StateName]
    UNION ALL
    SELECT 2 AS [StateID], 'In Progress' AS [StateName]
    UNION ALL
    SELECT 3 AS [StateID], 'Completed' AS [StateName]
    UNION ALL
    SELECT 4 AS [StateID], 'Aborted' AS [StateName]
    UNION ALL
    SELECT 5 AS [OutcomeId], 'To Be Determined (5)' AS [StateName]
    UNION ALL
    SELECT 6 AS [StateID], 'Needs Investigation' AS [StateName]
    SELECT
    TR.[ProjectId] AS [Project Id],
    P.[ProjectName],
    TR.[TestPlanId] AS [Plan Id],
    TP.Name AS [TestPlanName],
    TR.[TestRunId] AS [Run Id],
    TR.[Title],
    S.[StateID] AS [State Id],
    S.[StateName] AS [State],
    TR.[StartDate] AS [Date Started],
    TR.[CompleteDate] AS [Date Completed],
    DATEDIFF(SECOND, TR.[StartDate], TR.[CompleteDate]) AS Duration,
    TR.[Type],
    TR.[IsAutomated],
    TR.[TotalTests] AS [Total],
    TR.[PassedTests] AS [Passed],
    TR.[IncompleteTests] AS [Incomplete],
    TR.[UnanalyzedTests] AS [Unanalyzed],
    TR.[NotApplicableTests] AS [Not Applicable]
    FROM
    [Tfs_DefaultCollection].[dbo].[tbl_TestRun] AS TR
    INNER JOIN [Tfs_DefaultCollection].[dbo].[tbl_Project] AS P ON TR.ProjectId = P.ProjectId
    INNER JOIN [Tfs_DefaultCollection].[dbo].[tbl_Plan] AS TP ON TR.TestPlanId = TP.PlanId
    INNER JOIN cte_State AS S ON TR.[State] = S.[StateID]
    WHERE
    TR.TestRunId IN $($TestRuns)
    ORDER BY
    TR.[StartDate]
    $Command.CommandText = $SQLStatement
    $Command.Connection = $Connection
    $Command.CommandTimeout = 30
    $DataAdapter = New-Object System.Data.SqlClient.SqlDataAdapter
    $DataAdapter.SelectCommand = $Command
    $DataSet = New-Object System.Data.DataSet
    $DataAdapter.Fill($DataSet) | Out-Null
    Write-Output "$SQLStatement" | Out-File -FilePath $LogFile -Append
    # --DEBUG ONLY--> $DataSet.Tables[0]
    return $DataSet
    5. Extract record set of test results from TFS via SQL query:
    # FUNCTION: Retrieve-TestRunResults
    # Parameters:
    # (1.) LogFile -- Name of log file (e.g., C:\Temp or C:\Temp\DEPLOY_DatabaseServer_WebCMS2_DF06_20131031.6.log)
    # (2.) Connection -- Database connection
    # (3.) ListTestRunID -- List of test run identifiers
    Function Retrieve-TestRunResults
    param
    [Parameter(Mandatory=$True)][String]$LogFile,
    [Parameter(Mandatory=$True)]$Connection,
    [Parameter(Mandatory=$True)][String]$ListTestRunID
    Write-Output '--------------------------------------------------------------------------------' | Out-File -FilePath $LogFile -Append
    Write-Output "Retrieve test result(s): " | Out-File -FilePath $LogFile -Append
    Write-Output '--------------------------------------------------------------------------------' | Out-File -FilePath $LogFile -Append
    $TestRuns = '(' + $ListTestRunID + ')'
    $Command = New-Object System.Data.SqlClient.SqlCommand
    $SQLStatement = "
    WITH
    cte_Outcome
    AS
    SELECT 0 AS [OutcomeId], 'To Be Determined (0)' AS [OutcomeName]
    UNION ALL
    SELECT 1 AS [OutcomeId], 'In Progress' AS [OutcomeName]
    UNION ALL
    SELECT 2 AS [OutcomeId], 'Passed' AS [OutcomeName]
    UNION ALL
    SELECT 3 AS [OutcomeId], 'Failed' AS [OutcomeName]
    UNION ALL
    SELECT 4 AS [OutcomeId], 'Inconclusive' AS [OutcomeName]
    UNION ALL
    SELECT 5 AS [OutcomeId], 'To Be Determined (5)' AS [OutcomeName]
    UNION ALL
    SELECT 6 AS [OutcomeId], 'Aborted' AS [OutcomeName]
    UNION ALL
    SELECT 7 AS [OutcomeId], 'Blocked' AS [OutcomeName]
    UNION ALL
    SELECT 8 AS [OutcomeId], 'Not Executed' AS [OutcomeName]
    UNION ALL
    SELECT 10 AS [OutcomeId], 'Error' AS [OutcomeName]
    UNION ALL
    SELECT 11 AS [OutcomeId], 'Not Applicable' AS [OutcomeName]
    UNION ALL
    SELECT 12 AS [OutcomeId], 'Paused' AS [OutcomeName]
    UNION ALL
    SELECT 13 AS [OutcomeId], 'To Be Determined (13)' AS [OutcomeName]
    UNION ALL
    SELECT 255 AS [OutcomeId], 'Never Run' AS [OutcomeName]
    cte_State
    AS
    SELECT 0 AS [StateID], 'None' AS [StateName]
    UNION ALL
    SELECT 1 AS [StateID], 'Ready' AS [StateName]
    UNION ALL
    SELECT 2 AS [StateID], 'Completed' AS [StateName]
    UNION ALL
    SELECT 3 AS [StateID], 'Not Ready' AS [StateName]
    UNION ALL
    SELECT 4 AS [StateID], 'In Progress' AS [StateName]
    UNION ALL
    SELECT 5 AS [StateID], 'To Be Determined' AS [StateName]
    SELECT DISTINCT
    TR.[TestRunId] AS [Run Id],
    TR.[TestCaseId] AS [Case Id],
    O.[OutcomeID] AS [Outcome Id],
    O.[OutcomeName] AS [Outcome],
    S.[StateID] AS [State Id],
    S.[StateName] AS [State],
    TR.[TestCaseTitle] AS [Title],
    TR.[AutomatedTestName] AS [Automation Method],
    TR.[DateStarted] AS [Date Started],
    TR.[DateCompleted] AS [Date Completed],
    DATEDIFF(SECOND, TR.[DateStarted], TR.[DateCompleted]) AS Duration,
    TR.[FailureType] AS [Failure Type],
    TR.[ErrorMessage] AS [Error]
    FROM
    [Tfs_DefaultCollection].[dbo].[tbl_TestResult] AS TR
    INNER JOIN cte_Outcome AS O ON TR.Outcome = O.OutcomeID
    INNER JOIN cte_State AS S ON TR.State = S.StateID
    WHERE
    TR.TestRunId IN $($TestRuns)
    ORDER BY
    TR.[TestRunId],
    O.[OutcomeName],
    TR.[TestCaseTitle]
    $Command.CommandText = $SQLStatement
    $Command.Connection = $Connection
    $Command.CommandTimeout = 30
    $DataAdapter = New-Object System.Data.SqlClient.SqlDataAdapter
    $DataAdapter.SelectCommand = $Command
    $DataSet = New-Object System.Data.DataSet
    $DataAdapter.Fill($DataSet) | Out-Null
    Write-Output '--------------------------------------------------------------------------------' | Out-File -FilePath $LogFile -Append
    Write-Output "SQL Statement: " | Out-File -FilePath $LogFile -Append
    Write-Output '--------------------------------------------------------------------------------' | Out-File -FilePath $LogFile -Append
    Write-Output "$SQLStatement" | Out-File -FilePath $LogFile -Append
    # --DEBUG ONLY--> $DataSet.Tables[0]
    return $DataSet
    6. Email results to distribution list  
        Currently, I'm simplifying the extraction of suite path ... replacing hardcoded depth with STUFF() & XML PATH
    Carl.

  • SQL query problem - select max (case... aggregate function)

    Hi,
    I have a problem with below sql query, it gives me problem/error message 'ORA-00937: not a single-group group function', why?
    select sag.afdeling, sag.sagsnr, to_char(sag.start_dato, 'yyyy-mm-dd'), sag.stat, BOGF_TRANS.TRANSTYPE,
    max (case when BOGF_TRANS.TRANSTYPE = 'K' then sum(bogf_trans.belobdkk) end) + -- as "TRANSTYPE K",
    max (case when BOGF_TRANS.TRANSTYPE = 'D' then sum(bogf_trans.belobdkk) end) as "TRANSTYPE K & D",
    max (case when BOGF_TRANS.TRANSTYPE = 'S' then sum(bogf_trans.belobdkk) end) as "SUM TRANSTYPE S"
    from sag
    join bogf_trans on sag.selskab = bogf_trans.selskab and sag.sagsnr = bogf_trans.sagsnr and sag.afdeling = bogf_trans.afdeling
    where SAG.SELSKAB=37 and SAG.AFDELING = 'SUS' AND SAG.SAGSNR = 10876
    group by sag.afdeling, sag.sagsnr, sag.start_dato, sag.stat, BOGF_TRANS.TRANSTYPE
    If I exclude (columns) as below it give me correct summations (max (case... sum(...)) but then I miss some important info that I need
    select
    max (case when BOGF_TRANS.TRANSTYPE = 'K' then sum(bogf_trans.belobdkk) end) + -- as "TRANSTYPE K",
    max (case when BOGF_TRANS.TRANSTYPE = 'D' then sum(bogf_trans.belobdkk) end) as "TRANSTYPE K & D",
    max (case when BOGF_TRANS.TRANSTYPE = 'S' then sum(bogf_trans.belobdkk) end) as "SUM TRANSTYPE S"
    from sag
    join bogf_trans on sag.selskab = bogf_trans.selskab and sag.sagsnr = bogf_trans.sagsnr and sag.afdeling = bogf_trans.afdeling
    where SAG.SELSKAB=37 and SAG.AFDELING = 'SUS' AND SAG.SAGSNR = 10876
    group by sag.afdeling, sag.sagsnr, sag.start_dato, sag.stat, BOGF_TRANS.TRANSTYPE
    Any ideas?

    Moved to more sutable forum, sorry.

  • PL/SQL function body return sql query, no data found problem

    Hi all,
    we are trying to build a dynamic report based on item selection by user. we are using SQL Query (PL/SQL function body returning SQL query). However when a user change the item and submit the page . The following error appears.
    ORA-01403: no data found.
    our query is so simple
    declare
    l_query varchar2(30000) default 'select id from chw';
    begin
    if(:P11_PARA=1) then
    l_query:='select name from chw';
    end if;
    return l_query;
    end;
    any quick help please.

    Hello Mike,
    I tried it, the problem still exists.
    ORA-01403: no data found
    my new code is
    declare
    l_query varchar2(30000) default 'select id from chw';
    begin
    if (nvl(TO_NUMBER(:P11_PARA),0) = 1) then
    l_query:='select name from chw';
    end if;
    return (l_query);
    end;
    note, there is no process in this page.
    Edited by: M.Jabr on Oct 14, 2009 6:13 AM

Maybe you are looking for

  • Question related to String

    Hi All, Please answer my questions below. if you have a String of 256 bits, what can be the maximum length of it Thanks in advance,

  • New N73 Firmware V 4.0839.42.2.1 Problems

    After updating my phone, 1st i noticed that the startup time just get better but, all problems come one after one; 1) the battery life have been ruined . 2) in making a call sometimes the phone hangs and there is no solution but removing the battery.

  • TA48312 I use a 6 year old iBook G4.  It has gotten slow.  The wheel just spins.  Can someone help me?

    I am 89 years young.  I use a 6 year old iBook G4.  It has gotten slower than me.  I can't open firefox anymore.  I can't get to google in Safari.  The wheel just spins.  Can someone help me?  <Email Edited By Host>

  • Can't find my iBook I published into iTunes

    Hi everyone:) I've got the following problem: I have created a book, downloaded Producer, ran through the process of publishing and all seemed to have been done with a 'Successful upload' to iTunes information. But when I go to iTunes I can't find my

  • Check Version!

    Hi, How to check the version of my current portal server using? Thanks! null