Consolidating multiple rows in 1 row, question with my SQL query

Hi, quick question.. I have a table with the following structure and data:
Table TEST
Usr id | Start Time | End Time | Dep_id |
123 | 8:00 | 10:00 | 1
123 | 10:00 | 12:00 | 1
548 | 12:00 | 14:00 | 2
549 | 10:00 | 12:00 | 3
549 |8:00 | 10:00 | 3
550 | 12:00 | 14:00 | 3
I need to consolidate start time and end time,
where the dep_id is the same,
and the usr Id is the same,
and start time = end Time.
The result will be something like:
Usr id | Start Time | End Time | Dep_id |
123 | 8:00 | 12:00 | 1
548 | 12:00 | 14:00 | 2
549 | 8:00 | 12:00 | 3
550 | 12:00 | 14:00 | 3
I'm doing something like:
SELECT MIN(START_TIME) START_TIME,
MAX(END_TIME) END_TIME,
DEP_ID
FROM TEST
GROUP BY DEP_ID;
This is consolidating, but I don't know how to add the conditions so it doesn't consolidate the last 3 rows in 1 (only 2 can be consolidated, the last row has a different usr_id)
anyone has a suggestion/solution?
thanks!

This is not a full solution but may give you a way to complete
You may spit it to two SELECT with UNION ALL (based on gap you have)
WITH temp AS
     (SELECT '123' user_id, 8 start_t, 10 end_t, 1 dept
        FROM DUAL
      UNION ALL
      SELECT '123' user_id, 10 start_t, 12 end_t, 1 dept
        FROM DUAL
      UNION ALL 
      SELECT '548' user_id,  12 start_t, 14 end_t, 2 dept
        FROM DUAL
      UNION ALL 
      SELECT '549' user_id,  10 start_t, 12 end_t, 3 dept         
        FROM DUAL
      UNION ALL 
      SELECT '549' user_id,   8 start_t, 10 end_t, 3 dept         
        FROM DUAL             
      UNION ALL 
      SELECT '550' user_id,   12 start_t, 14 end_t, 3 dept         
        FROM DUAL             
      UNION ALL 
      SELECT '549' user_id,   16 start_t, 18 end_t, 3 dept         
        FROM DUAL                          
SELECT du, start_t, end_t, next_st_t - end_t gap FROM (
SELECT  dept||user_id du, start_t, end_t, LEAD (start_t)
OVER (PARTITION BY dept||user_id ORDER BY start_t) next_st_t from temp
DU                                          START_T                                END_T                                  GAP                                   
1123                                        8                                      10                                     0                                     
1123                                        10                                     12                                                                           
2548                                        12                                     14                                                                           
3549                                        8                                      10                                     0                                     
3549                                        10                                     12                                     4                                     
3549                                        16                                     18                                                                           
3550                                        12                                     14                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

Similar Messages

  • Question with PL - SQL Query.

    I have following table named ProductStatus with values.....
    ID.....Number.....Status.....Date
    1.....     08-0001.....     New.....     04/01/2008 05:04:00:000
    2.....     08-0001..... New.....     04/01/2008 08:06:00:000
    3.....     08-0001.....     New.....     04/01/2008 09:01:00:000
    4.....     08-0001.....     Open..... 04/01/2008 10:12:00:000
    5.....     08-0001.....     Closed... 04/05/2008 10:12:00:000
    6.....     08-0002.....     New.....     04/02/2008 10:12:00:000
    What i want is....
    All the Rows(*) Where
    1). Date < 02-APR-08 ( 04/02/2008 )
    2). if there is similar Number then it should get only last status of that number (Means based on date it should get last status only)
    Please Help me...
    Thanks...
    regards,
    j@y

    Sorry ...my Mistake here with column types...
    Here it is corrected....
    -- Create Table
    CREATE TABLE ProductStatus
    ID NUMBER(4,0),
    Num VARCHAR2(20),
    Status VARCHAR2(20),
    StatusDate TIMESTAMP
    -- Add Test Data
    insert into ProductStatus(ID,Num,Status,StatusDate) Values (1,'08-0001','New',timestamp'2008-04-01 09:00:00.123456789');
    insert into ProductStatus(ID,Num,Status,StatusDate) Values (2,'08-0001','New',timestamp'2008-04-01 05:04:00.123456789');
    insert into ProductStatus(ID,Num,Status,StatusDate) Values (3,'08-0001','New',timestamp'2008-04-01 08:06:00.123456789');
    insert into ProductStatus(ID,Num,Status,StatusDate) Values (4,'08-0001','Open',timestamp'2008-04-01 10:10:00.123456789');
    insert into ProductStatus(ID,Num,Status,StatusDate) Values (5,'08-0002','New',timestamp'2008-04-05 10:12:00.123456789');
    insert into ProductStatus(ID,Num,Status,StatusDate) Values (6,'08-0003','New',timestamp'2008-04-02 11:22:00.123456789');
    Select All the Rows(*) Where
    1). StatusDate < 02-APR-08 ( 04/02/2008 )
    Select * from ProductStatus where StatusDate < to_date('02-Apr-08');
    2). if there is similar Num then it should get only last status of that Num (Means based on date it should get last status only)
    Confused with this..how to implement !!!!
    Thanks,
    regards,
    j@y

  • Multiple row subquery with like operator

    can any1 give me an example where we can use a multiple row subquery with the like operator.I read it can be used but when i tried it gives the following error
    select * from gagan_emp where ename like (select ename from gagan_emp where deptno=10)
    ERROR at line 1:
    ORA-01427: single-row subquery returns more than one row

    The right part of 'LIKE' is permitted only single value expression
    (including subquery that returns single value),
    is not permitted multiple values.
    -- Examples (but.... not so good)
    select * from gagan_emp e0
    where exists
    (select ename from gagan_emp e1 where deptno=10
    and e0.ename like e1.ename)
    select * from gagan_emp e0
    where exists
    (select ename from gagan_emp e1 where deptno=10
    and e0.ename = e1.ename)
    select * from gagan_emp e0
    where ename = any
    (select ename from gagan_emp e1 where deptno=10)
    select * from gagan_emp
    where ename like
    (select ename from gagan_emp e1 where deptno=10 and rownum=1)
    ;

  • [Forum FAQ] How do I send multiple rows returned by Execute SQL Task as Email content in SQL Server Integration Services?

    Question:
    There is a scenario that users want to send multiple rows returned by Execute SQL Task as Email content to send to someone. With Execute SQL Task, the Full result set is used when the query returns multiple rows, it must map to a variable of the Object data
    type, then the return result is a rowset object, so we cannot directly send the result variable as Email content. Is there a way that we can extract the table row values that are stored in the Object variable as Email content to send to someone?
    Answer:
    To achieve this requirement, we can use a Foreach Loop container to extract the table row values that are stored in the Object variable into package variables, then use a Script Task to write the data stored in packages variables to a variable, and then set
    the variable as MessageSource in the Send Mail Task. 
    Add four variables in the package as below:
    Double-click the Execute SQL Task to open the Execute SQL Task Editor, then change the ResultSet property to “Full result set”. Assuming that the SQL Statement like below:
    SELECT   Category, CntRecords
    FROM         [table_name]
    In the Result Set pane, add a result like below (please note that we must use 0 as the result set name when the result set type is Full result set):
    Drag a Foreach Loop Container connects to the Execute SQL Task. 
    Double-click the Foreach Loop Container to open the Foreach Loop Editor, in the Collection tab, change the Enumerator to Foreach ADO Enumerator, then select User:result as ADO object source variable.
    Click the Variable Mappings pane, add two Variables as below:
    Drag a Script Task within the Foreach Loop Container.
    The C# code that can be used only in SSIS 2008 and above in Script Task as below:
    public void Main()
       // TODO: Add your code here
                Variables varCollection = null;
                string message = string.Empty;
                Dts.VariableDispenser.LockForWrite("User::Message");
                Dts.VariableDispenser.LockForWrite("User::Category");
                Dts.VariableDispenser.LockForWrite("User::CntRecords");     
                Dts.VariableDispenser.GetVariables(ref varCollection);
                //Format the query result with tab delimiters
                message = string.Format("{0}\t{1}\n",
                                            varCollection["User::Category"].Value,
                                            varCollection["User::CntRecords"].Value
               varCollection["User::Message"].Value = varCollection["User::Message"].Value + message;   
               Dts.TaskResult = (int)ScriptResults.Success;
    The VB code that can be used only in SSIS 2005 and above in Script Task as below, please note that in SSIS 2005, we should
    change PrecompileScriptIntoBinaryCode property to False and Run64BitRuntime property to False
    Public Sub Main()
            ' Add your code here
            Dim varCollection As Variables = Nothing
            Dim message As String = String.Empty
            Dts.VariableDispenser.LockForWrite("User::Message")
            Dts.VariableDispenser.LockForWrite("User::Category")
            Dts.VariableDispenser.LockForWrite("User::CntRecords")
            Dts.VariableDispenser.GetVariables(varCollection)
            'Format the query result with tab delimiters
            message = String.Format("{0}" & vbTab & "{1}" & vbLf, varCollection("User::Category").Value, varCollection("User::CntRecords").Value)
            varCollection("User::Message").Value = DirectCast(varCollection("User::Message").Value,String) + message
            Dts.TaskResult = ScriptResults.Success
    End Sub
    Drag Send Mail Task to Control Flow pane and connect it to Foreach Loop Container.
    Double-click the Send Mail Task to specify the appropriate settings, then in the Expressions tab, use the Message variable as the MessageSource Property as below:
    The final design surface like below:
    References:
    Result Sets in the Execute SQL Task
    Applies to:
    Integration Services 2005
    Integration Services 2008
    Integration Services 2008 R2
    Integration Services 2012
    Integration Services 2014
    Please click to vote if the post helps you. This can be beneficial to other community members reading the thread.

    Thanks,
    Is this a supported scenario, or does it use unsupported features?
    For example, can we call exec [ReportServer].dbo.AddEvent @EventType='TimedSubscription', @EventData='b64ce7ec-d598-45cd-bbc2-ea202e0c129d'
    in a supported way?
    Thanks! Josh

  • Help with an SQL Query on the Logger

    We are running UCCE 8.5(3) and need help with an SQL query. When I run the below I would also like to see skill group information(name preferably)? Any help would be greatly appreciated!
    select * from dbo.t_Termination_Call_Detail where DateTime between '10-11-2012 00:00:00:00' and
    '10-11-2012 23:59:59:59'

    David, thanks for replying.  Unfortunitly I don't know enough about SQL to put that into a query and have it return data.  Would you be able to give an example on what the query would look like?

  • Insert multiple rows question

    Hi!
    I need to insert multiple rows into a table with one run, but each row must have its unique id(PK). There is a sequence and a trigger
    in our database (11gR1) that get the next value. So, my question is: Is it possible to do a "bulk insert", maybe with a for loop cursor?
    Thanks for your feedback!

    user545194 wrote:
    Hi!
    I need to insert multiple rows into a table with one run, but each row must have its unique id(PK). There is a sequence and a trigger
    in our database (11gR1) that get the next value. So, my question is: Is it possible to do a "bulk insert", maybe with a for loop cursor?No need for a loop cursor, just insert the rows using an INSERT ... SELECT ... statement. If you have a row based trigger putting a sequence on the rows then it will allocated the id's accordingly.

  • Multiple row insert with jsp

    Please i need help on how to enter multiple row into mysql with one insert
    statement and jsp , i have been trying this for weeks without sucess e.g
    <---- THIS AN EXAMPLE OF MY INSERT FORM ---->
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    </head>
    <body>
    <form id="form1" name="form1" method="post" action="some sort of jsp page">
    mike : <input type="text" name="staffid" />
    john : <input type="text" name="staffid" />
    peter :<input type="text" name="staffid" />
    james :<input type="text" name="staffid" />
    jerry :<input type="text" name="staffid" />
    mikel: <input type="text" name="staffid" />
    <input name="submit" type="button" />
    </form>
    </body>
    </html>
    <--MY DATABASE LOOKS LIKE --->
    name | staffid |
    | |
    | |
    | |
    I have been looking for a way to enter only the value or all the values that is entered by
    the user.

    ODAFEONIHOWO wrote:
    Please i need help on how to enter multiple row into mysql with one insert
    statement and jsp it's not possible - you'll need to do a batch insert
    i have been trying this for weeks without sucess e.g how much experience do you have with Java?

  • How can I move to row number with a search Query

    Hi everybody,
    Does anybody know how can I located a record in a multiple block, with a SQL sentence, using bind variables.
    Thanks in adviced

    Welcome to the Apple Discussions!
    Unfortunately, since Front Row has no preferences you can actually change, there's no way to change the screen now. (Besides the work arounds you've already discovered.) I would send Apple some Mac OS X feedback (since Front Row is considered part of OS X, not a stand-alone application) and let them know you'd like to be able specify the screen. You're not the first person here to ask for that option.
    http://www.apple.com/macosx/feedback/
    -Doug

  • Inserting multiple rows into DB via SQL insert or stored procedure?

    I have successfully created an application where I select a row in an output table view from a Microsoft Access DB SQL data source, and get an Oracle stored procedure to save the row in a new table in our Oracle DB.
    This works like a charm when selecting one single row in the table view. What I really need though is for the procedure to save multiple rows at once.
    My table is configured with selection mode = 'multiple', and the data mapping line between the table and my procedure has mapping scope = 'selected data rows'.
    So, I am able to select multiple rows but still my procedure only stores one of the values sent. Does anyone know if this is related to my procedure not handling multiple parameter entries or if it's related to how VC outputs data to a procedure?
    Here is output from runtime flex log where you see the three values: 3, 11 and 9 that is sent to the procedure's IN parameter 'P_ID'.
    <Row OWNAPPS_TESTSQL_HYTTER_P_ID="3"/><Row OWNAPPS_TESTSQL_HYTTER_P_ID="11"/><Row OWNAPPS_TESTSQL_HYTTER_P_ID="9"/>
    Please help
    Henning Strand
    I am still very, very interested in hearing if anyone has been successful at passing multiple rows to a stored procedure in one submit action.
    Edited by: Henning Strand on Apr 11, 2008 1:58 PM

    Update for all you happy people using Oracle stored procedures with Visual Composer:
    When trying to run a simple procedure that accepts arrays as input parameters, the JDBC connector returns an error message saying: 'PLS-00306: wrong number or types of arguments in call ...'
    I registered this as a customer message with sap support and got an answer back saying:
    Unfotunately our JDBC connector is still not able to work with SP that contain arrays, this is the reason for the behaviour that you're seeing.
    This are the bad news, the good news is that with WebServices we don't have this limitation, so you can achieve the same results by using a WS instead of the Store Procedure.
    I have asked if and when using stored procedures with arrays will be supported - waiting for answer.
    Henning Strand

  • Whats wrong with the sql query-- giving no rows selected

    i have a table audit_data with 4 columns , eff_m & end_m are declared as timestamp and the time stamp data is different for all the records
    Please advice as soon as possible as this is a production problem
    ORG_GRP_I grn_n ED_EFF_m (timestamp) ED_END_M OFV
    1 999 01-Jan-06 1 03-Aug-06 0 0
    1 999 28-Jul-06 0 04-Aug-06 1 0
    1 999 04-Aug-06 1 04-Aug-06 1 0
    1 999 04-Aug-06 0 6.08
    This query is giving no rows returned,even though there is data in database
    SELECT NVL(OFV,0)
    FROM audit_data ag
    WHERE ag.ORG_GRP_I = 1
    AND ag.GRN_N = 999
    AND (ag.ED_EFF_M,NVL(ag.ED_END_M,SYSDATE)) IN (SELECT MAX(ED_EFF_M),MAX(NVL(ED_END_M,SYSDATE))
    FROM audit_data ag2
    WHERE ag2.ORG_GRP_I= ag.org_grp_i
    AND ag2.grn_n=ag.grn_n
    AND To_Date(To_Char(ag2.ED_EFF_M,'MM/DD/YYYY'),'MM/DD/YYYY') <= TO_DATE(TO_CHAR('08/04/06','MM/DD/YYYY'),'MM/DD/YYYY')
    AND To_Date(To_Char(NVL(ag2.ED_END_M,SYSDATE),'MM/DD/YYYY'),'MM/DD/YYYY') >= TO_DATE(TO_CHAR('08/04/06','MM/DD/YYYY'),'MM/DD/YYYY'));
    This query is giving value 6.08, when made type conversions.
    what wrong with the above query.please advice
    SELECT NVL(OFV,0)
    FROM audit_data ag
    WHERE ag.ORG_GRP_I = 1
    AND ag.GRN_n = 999
    AND (to_date(to_char(ag.ED_EFF_M,'mm/dd/yyyy'),'mm/dd/yyyy'),NVL(to_date(to_char(ag.ED_END_M,'mm/dd/yyyy'),'mm/dd/yyyy'),SYSDATE)) IN
    (SELECT MAX(to_date(to_char(ED_EFF_M,'mm/dd/yyyy'),'mm/dd/yyyy')),MAX(NVL(ED_END_M,SYSDATE))
    FROM audit_data ag2
    WHERE ag2.ORG_GRP_I= ag.org_grp_i
    AND ag2.grn_n=ag.grn_n
    AND To_Date(To_Char(ag2.ED_EFF_M,'MM/DD/YYYY'),'MM/DD/YYYY') <= TO_date('08/04/2006','MM/DD/YYYY')
    AND To_Date(To_Char(NVL(ag2.ED_END_M,SYSDATE),'MM/DD/YYYY'),'MM/DD/YYYY') >= TO_DATE('08/04/2006','MM/DD/YYYY'));

    In the second query you convert a string to a date correctly using TO_DATE(string,date format)
    In the first query you try to make a char of something that already is a char, e.g. TO_CHAR('08/04/06','MM/DD/YYYY').
    The TO_CHAR functions expects either a number or a date as its first parameter. That's why it's giving you a ORA-01722.

  • Obtain rows from a complex sql query

    Hi to all, please somebody who can help me, my scenario is as next:
    One table like next
    Reservation (table)
    Boat (string)
    reservation (date)
    class (string)
    room1_cod (int)
    room1 (int)
    room2_cod (int)
    room2 (int)
    room3_cod (int)
    room3 (int)
    In room(x)_cod , I am saving a client code, in the room(x) , I am saving the price of the room for that client.
    example:
    LUSITANIA, 2014-3-1, MEDIUM, 0, 0, 145, 345, 0, 0    = client 145 ocupied room 2 paying $345
    LUSITANIA, 2014-2-1, MEDIUM, 145, 345, 0, 0, 0, 0    = client 145 ocupied room 1 paying $345
    LUSITANIA, 2014-1-1, MEDIUM, 0, 0, 0, 0, 145, 345    = client 145 ocupied room 3 paying $345
    how would like to make an sql query for filter :
    (Boat, reservation, class... with a reservation start date and finish date and with an specific "client code" find and filter this code into room1_cod , room2_cod and room3_cod .... and maybe do a temporarly table with rows containing (Boat, Reservation,
    Class, "client_code" , "client_pay" )
    Resulting LIKE:
    LUSITANIA, 2014-3-1, MEDIUM, 145, 345
    LUSITANIA, 2014-2-1, MEDIUM, 145, 345
    LUSITANIA, 2014-1-1, MEDIUM, 145, 345
    Please I need your guidance. TKS

    Please take a look
    SELECT Boat, reservation, class,
    case
    when room1_cod>0 then 1
    when room2_cod>0 then 2
    when room3_cod>0 then 3
    end as Room,
    case
    when room1_cod>0 then room1_cod
    when room2_cod>0 then room2_cod
    when room3_cod>0 then room3_cod
    end as client_code,
    case
    when room1>0 then room1
    when room2>0 then room2
    when room3>0 then room3
    end as client_pay
    from
    SELECT 'LUSITANIA' AS Boat, CONVERT(DATE,'2014-3-1',121) AS reservation, 'MEDIUM' AS class, 0 AS room1_cod, 0 AS room1, 145 AS room2_cod, 345 AS room2, 0 AS room3_cod, 0 AS room3 ---//client 145 ocupied room 2 paying $345
    union all
    SELECT 'LUSITANIA' AS Boat, CONVERT(DATE,'2014-2-1',121) AS reservation, 'MEDIUM' AS class, 145 AS room1_cod, 345 AS room1, 0 AS room2_cod, 0 AS room2, 0 AS room3_cod, 0 AS room3 --//= client 145 ocupied room 1 paying $345
    union all
    SELECT 'LUSITANIA' AS Boat, CONVERT(DATE,'2014-1-1',121) AS reservation, 'MEDIUM' AS class, 0 AS room1_cod, 0 AS room1, 0 AS room2_cod, 0 AS room2, 145 AS room3_cod, 345 AS room3 --//= client 145 ocupied room 3 paying $345
    ) as Reservation
    ----Better table design would eliminate multiple columns for each room/client code/rate like the following
    SELECT
    Boat, reservation, class,
    Room,
    room_cod as client_code,
    room_rate as client_pay
    from
    SELECT 'LUSITANIA' AS Boat, CONVERT(DATE,'2014-3-1',121) AS reservation, 'MEDIUM' AS class, 2 AS room, 145 AS room_cod, 345 AS room_rate ---//client 145 ocupied room 2 paying $345
    union all
    SELECT 'LUSITANIA' AS Boat, CONVERT(DATE,'2014-2-1',121) AS reservation, 'MEDIUM' AS class, 1 AS room, 145 AS room_cod, 345 AS room_rate --//= client 145 ocupied room 1 paying $345
    union all
    SELECT 'LUSITANIA' AS Boat, CONVERT(DATE,'2014-1-1',121) AS reservation, 'MEDIUM' AS class, 3 AS room, 145 AS room_cod, 345 AS room_rate --//= client 145 ocupied room 3 paying $345
    ) as Reservation
    thanks for you effort, best regards

  • Flash chart with dynamic sql query does not display

    Hi,
    In my schema SIVOA I have a lot of tables declared like this :
      CREATE TABLE "SIVOA"."EVV_xxxx"
       (     "CLEF_VAR" NUMBER(4,0),
         "DATE1" DATE,
         "VALEUR" NUMBER(16,8) Only the last part of the name changes "xxxx". For example E009, E019, etc....
    I am making a chart page with report and want the user to select a name of a table and I will display using dynamic sql query, the table report and chart.
    P184_ENAME is a select list returning the last part of the name of the table, fro example 'E009', 'E019', etc.
    P8_CLEF_VAR is an item containing a value. This value is a key retrieved like this :SELECT CLEF_VAR
    FROM SIVOA.SITE_ECHELLE
    WHERE SITE = :P184_ENAMEI built a classic report using a sql dynamic function :DECLARE
    x VARCHAR2 (4000);
    BEGIN
    x := 'SELECT NULL, DATE1, VALEUR FROM SIVOA.EVV_'
    || UPPER(:p184_ename)
    || ' WHERE CLEF_VAR = :p8_clef_var' ;
    RETURN (x);
    END;:p8_clef_var is an itme containing the value '4544'.
    This works perfectly fine !
    When I use this sql fucytion into a flash chart it does not work. I get this message "No data found".
    I do not understand why a the report get a result and not the chart !
    But if i hard-code the number of the CLEF_VAR instead of fetching it from :p8_clef_var I get a nice chart ! Go figure !DECLARE
    x VARCHAR2 (4000);
    BEGIN
    x := 'SELECT NULL, DATE1, VALEUR FROM SIVOA.EVV_'
    || UPPER(:p184_ename)
    || ' WHERE CLEF_VAR = 4544 ' ;
    RETURN (x);
    I cannot stay with the key (CLEF_VAR) hard-coded unformtunately !
    My question is how to get the chart displaying properly ??
    Thank you for your kind answers.
    Christian                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    Alex,
    Using your request, with the classic report I get results (data), but I get the same message with the Flash chart : "No data found" ! I don't know how to investigate this. i tried many things but nothing works.
    Christian
    PS I tried this :
    DECLARE
       X   VARCHAR2 (4000);
    BEGIN
    x := 'SELECT NULL, DATE1, ROUND(VALEUR,2) FROM SIVOA.EVV_'
          || UPPER (:p184_ename) ||
          ' WHERE CLEF_VAR = '
          || :p8_clef_var ||
          ' AND DATE1 BETWEEN TO_DATE ('''
    ||:P8_DATE_DEBUT||''', ''DD/MM/YYYY HH24:MI'') AND TO_DATE ('''
    ||:P8_DATE_FIN||''', ''DD/MM/YYYY HH24:MI'')'
    RETURN (X);
    END; But it does not work either. I could find that the SLQ syntax generated is good becaus I put it into an item which display the return done by the pls/sql.
    What is sttange also with the classic report is that if I do click on next or previous to see another rows, I get the message "No data found". If I try to export the report I get an excel file with "No data fouid".
    Does anybody already tried my "need" here ? i find strange thant I should not be the firs one trying to get a report an tables which name would be "dynamic".
    Tahnk you.
    Edited by: Christian from France on Feb 13, 2009 3:05 AM

  • Help with T-SQL query

    I have 3 hierarchical tables. [Parent] ->[Child1]->[Child2]
    I have [Xref] table which stores the documents associated with these three tables. In the [Xref] table, the column “TypeID” defines to which table the document is associated with.
    Below is the table structure with some sample data.
    Question: Given parented I want to get all the documents associated with parent as well its children. My sql query uses Union and its working fine. But Is there any other simple way to re-write this query?
    (Note that this is just an example, the actual hierarchy is pretty long so my SQL is getting little messy and I want simplify it.)
    TYPES
    TypeID TypeName
    1 Parent
    2 Child1
    3 Child2
    TABLE - PARENT
    ParentID
    1
    2
    3
    TABLE - CHILD1
    Child1ID ParentID
    1 1
    2 1
    3 2
    TABLE - CHILD2
    Child2ID Child1ID
    1 1
    2 1
    3 2
    4 2
    XREF
    DocumentID TypeID LocatorID
    1 1 1
    2 1 2
    3 1 3
    4 2 1
    5 2 2
    6 2 3
    7 3 1
    8 3 2
    9 3 3
    10 3 4
    SELECT DocumentID FROM XREF X
    JOIN Parent P ON P.ParentID = x.LocatorID AND TypeID = 1 -- Parent
    WHERE P.ParentID = @ParentID
    UNION
    SELECT DocumentID FROM XREF X
    JOIN Child1 C1 ON C1.Child1ID = x.LocatorID AND TypeID = 2 -- Child1
    JOIN Parent P ON P.ParnetID = C1.ParentID
    WHERE P.ParentID = @ParentID
    UNION
    SELECT DocumentID FROM XREF X
    JOIN Child2 C2 ON C2.Child1ID = x.LocatorID AND TypeID = 3 -- Child2
    JOIN Child1 C1 ON C1.Child1ID = c2.Child1ID
    JOIN Parent P ON P.ParnetID = C1.ParentID
    WHERE P.ParentID = @ParentID

    Can you child span multiple levels? If yes, best way would be to use CTE
    see
    http://technet.microsoft.com/en-us/library/ms186243(v=sql.105).aspx
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • Incorrectly read attributes with custom SQL query

    Hi folks,
    I'm trying to read in a random sampling of records from a table, so I tried:
    ReadAllQuery q = new ReadAllQuery();
    q.setReferenceClass(Foo.class);
    q.addPartialAttribute("bar");
    q.setSQLString("select * from Foo sample(10)");
    q.useCursoredStream(100,100, new ValueReadQuery("select count(*) from Foo sample(10)"));
    This all worked fine, the Foos were retrieved, but after the first dozen or so, all the "bar" attributes were null, which they should not be. This only occurs when using a custom SQL string. I tried bringing back all the objects (i.e., without using setSQLString) and examining them and all the "bar"s were present. But when I use setSQLString the attributes don't get read correctly.
    Can anyone tell me what I'm doing wrong? Is there a better way to do it?
    Thanks,
    Bryn

    Okay, here's the actual code:
    ReadAllQuery q = new ReadAllQuery();
    q.setReferenceClass(ActivityCenter.class);
    boolean useCustom = true;
    if (useCustom) {
    q.setSQLString("SELECT SetupDt, TerminationDt, ReinstateDt, IID, upDt, ID, " +
    "Stat, SubType, Acct FROM ACtr");
    q.useCursoredStream(100,100, new ValueReadQuery("select count(IID) from actr"));
    } else {
    q.useCursoredStream(100,100);
    session.logMessages();
    activityCenters = (CursoredStream) session.executeQuery(q);
    ActivityCenter ac = (ActivityCenter) activityCenters.read();
    if (ac.getAccount() == null) {
    System.err.println(ac.getID() + ": Oops!");
    } else {
    System.err.println(ac.getID() + ": Has account!");
    System.exit(0);
    So, everything about this program is the same - how the mapping is done, how things get initialized, everything. The only difference is whether I use a custom SQL query or not. Here's what it looks like when I run it both ways:
    First, custom:
    DatabaseSession(2433702)--Connection(393272)--SELECT SetupDt, TerminationDt, ReinstateDt, IID, upDt, ID, Stat, SubType, Acct FROM ACtr
    1.1: Oops!
    Now, without the custom SQL:
    DatabaseSession(393272)--Connection(7896086)--SELECT SetupDt, TerminationDt, ReinstateDt, IID, upDt, ID, Stat, SubType, Acct FROM ACtr
    DatabaseSession(393272)--Connection(7896086)--SELECT
    //bunch of fields from the Acct attribute...
    FROM Acct WHERE (IID= 'ffbe5c47f3ea762cfd50fbe9e6d6de6')
    1.1: Has account!
    Notice that the first query on Actr is identical in both cases. Also note there are no null Actr.acct fields in the database:
    SQL> select * from actr where actr.acct is null;
    no rows selected
    SQL>
    This is on Oracle 9i, with the thin jdbc driver.
    Also, I was curious that you asked if I was using partial attributes - when I try to add a partial attribute when using the custom SQL string, I get exceptions like this one:
    java.lang.ClassCastException: oracle.toplink.internal.queryframework.CallQueryMechanism
    at oracle.toplink.queryframework.ObjectLevelReadQuery.initializeDefaultBuilder(Unknown Source)
    at oracle.toplink.queryframework.ObjectLevelReadQuery.getExpressionBuilder(Unknown Source)
    at oracle.toplink.queryframework.ObjectLevelReadQuery.addPartialAttribute(Unknown Source)
    at jenkon.magellan.util.MLMulator.getActivityCenters(MLMulator.java:782)
    at jenkon.magellan.util.MLMulator.run(MLMulator.java:897)
    at jenkon.magellan.util.MLMulator.main(MLMulator.java:943)
    Thanks,
    Bryn

  • Help with JSTL sql query

    i have a query that i want to pass a paramater to the query goes like this
    <sql:query var = "user" >
    SELECT AMOUNT,flag FROM SAVINGS_ACTIVITY_DETAILS WHERE ACCOUNT_ID =? AND AMOUNT >200000 AND Flag =1 AND ACCOUNT_ACTION_ID =6 AND Treated =0 ORDER BY created_date DESC
    <sql:param value="${test.accountId}"/>
    </sql:query>
    this will give an error on TLD attribute.................and i tested the value with the following code and it worked
    <c:set value="${test.accountId}" var="u"/>
    <c:out value="${u}"/>
    this will print out the value nicely now i need a way to be able to pass this value to the sql query
    Thanks

    Which version of jstl are you using? == JSTL1.1
    However the other two questions remain unanswered.
    What server are you using? Version?
    How are you importing the tag library?
    You can find out the server info with this snippet of a JSP:
    Working with server: <%= application.getServerInfo() %><br>
    Servlet Specification: <%= application.getMajorVersion() %>.<%= application.getMinorVersion() %> <br>
    JSP version: <%= JspFactory.getDefaultFactory().getEngineInfo().getSpecificationVersion() %><br>
    Java Version: <%= System.getProperty("java.version") %><br>

Maybe you are looking for