Need help with turning multiple rows into a single row

Hello.
I've come across a situation that is somewhat beyond my knowledge base. I could use a little help with figuring this out.
My situation:
I am attempting to do some reporting from a JIRA database. What I am doing is getting the dates and times for specific step points of a ticket. This is resulting in many rows per ticket. What I need to do is return one row per ticket with a calculation of time between each step. But one issue is that if a ticket is re-opened, I want to ignore all data beyond the first close date. Also, not all tickets are in a closed state. I am attaching code and a sample list of the results. If I am not quite clear, please ask for information and I will attempt to provide more. The database is 10.2.0.4
select jiraissue.id, pkey, reporter, summary
,changegroup.created change_dt
,dbms_lob.substr(changeitem.newstring,15,1) change_type
,row_number() OVER ( PARTITION BY jiraissue.id ORDER BY changegroup.created ASC ) AS order_row
from jiraissue
,changeitem, changegroup
,(select * from customfieldvalue where customfield = 10591 and stringvalue = 'Support') phaseinfo
where jiraissue.project = 10110
and jiraissue.issuetype = 51
and dbms_lob.substr(changeitem.newstring,15,1) in ('Blocked','Closed','Testing','Open')
and phaseinfo.issue = jiraissue.id
and changeitem.groupid = changegroup.id
and changegroup.issueid = jiraissue.id
order by jiraissue.id,change_dt
Results:
1     21191     QCS-91     Error running the Earliest-deadlines flight interface request/response message     2008-07-16 9:30:38 AM     Open     1
2     21191     QCS-91     Error running the Earliest-deadlines flight interface request/response message     2008-07-16 11:37:02 AM     Testing     2
3     21191     QCS-91     Error running the Earliest-deadlines flight interface request/response message     2010-06-08 9:14:52 AM     Closed     3
4     21191     QCS-91     Error running the Earliest-deadlines flight interface request/response message     2010-09-02 11:29:37 AM     Open     4
5     21191     QCS-91     Error running the Earliest-deadlines flight interface request/response message     2010-09-02 11:29:42 AM     Open     5
6     21191     QCS-91     Error running the Earliest-deadlines flight interface request/response message     2010-09-02 11:29:50 AM     Testing     6
7     21191     QCS-91     Error running the Earliest-deadlines flight interface request/response message     2010-09-02 11:29:53 AM     Closed     7
8     23234     QCS-208     System Baseline - OK button does not show up in the Defer Faults page for the System Engineer role      2008-10-03 10:26:21 AM     Open     1
9     23234     QCS-208     System Baseline - OK button does not show up in the Defer Faults page for the System Engineer role      2008-11-17 9:39:39 AM     Testing     2
10     23234     QCS-208     System Baseline - OK button does not show up in the Defer Faults page for the System Engineer role      2011-02-02 6:18:02 AM     Closed     3
11     23977     QCS-311     Tally Sheet - Reason Not Done fails to provide reason for unassigned tasks     2008-09-29 2:44:54 PM     Open     1
12     23977     QCS-311     Tally Sheet - Reason Not Done fails to provide reason for unassigned tasks     2010-05-29 4:47:37 PM     Blocked     2
13     23977     QCS-311     Tally Sheet - Reason Not Done fails to provide reason for unassigned tasks     2011-02-02 6:14:57 AM     Open     3
14     23977     QCS-311     Tally Sheet - Reason Not Done fails to provide reason for unassigned tasks     2011-02-02 6:15:32 AM     Testing     4
15     23977     QCS-311     Tally Sheet - Reason Not Done fails to provide reason for unassigned tasks     2011-02-02 6:15:47 AM     Closed     5

Hi,
Welcome to the forum!
StblJmpr wrote:
... I am attempting to do some reporting from a JIRA database. What is a JIRA database?
I am attaching code and a sample list of the results. If I am not quite clear, please ask for information and I will attempt to provide more. Whenever you have a question, please post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables involved, and the results you want from that data.
Simplify the problem as much as possible. For example, if the part you don't know how to do only involves 2 tables, then jsut post a question involving those 2 tables. So you might just post this much data:
CREATE TABLE     changegroup
(      issueid          NUMBER
,      created          DATE
,      id          NUMBER
INSERT INTO changegroup (issueid, created, id) VALUES (21191,  TO_DATE ('2008-07-16 09:30:38 AM', 'YYYY-MM-DD HH:MI:SS AM'),  10);
INSERT INTO changegroup (issueid, created, id) VALUES (21191,  TO_DATE ('2008-07-16 11:37:02 AM', 'YYYY-MM-DD HH:MI:SS AM'),  20);
INSERT INTO changegroup (issueid, created, id) VALUES (21191,  TO_DATE ('2010-06-08 09:14:52 AM', 'YYYY-MM-DD HH:MI:SS AM'),  90);
INSERT INTO changegroup (issueid, created, id) VALUES (21191,  TO_DATE ('2010-09-02 11:29:37 AM', 'YYYY-MM-DD HH:MI:SS AM'),  10);
INSERT INTO changegroup (issueid, created, id) VALUES (21191,  TO_DATE ('2010-09-02 11:29:42 AM', 'YYYY-MM-DD HH:MI:SS AM'),  10);
INSERT INTO changegroup (issueid, created, id) VALUES (21191,  TO_DATE ('2010-09-02 11:29:50 AM', 'YYYY-MM-DD HH:MI:SS AM'),  20);
INSERT INTO changegroup (issueid, created, id) VALUES (21191,  TO_DATE ('2010-09-02 11:29:53 AM', 'YYYY-MM-DD HH:MI:SS AM'),  90);
INSERT INTO changegroup (issueid, created, id) VALUES (23234,  TO_DATE ('2008-10-03 10:26:21 AM', 'YYYY-MM-DD HH:MI:SS AM'),  10);
INSERT INTO changegroup (issueid, created, id) VALUES (23234,  TO_DATE ('2008-11-17 09:39:39 AM', 'YYYY-MM-DD HH:MI:SS AM'),  20);
INSERT INTO changegroup (issueid, created, id) VALUES (23234,  TO_DATE ('2011-02-02 06:18:02 AM', 'YYYY-MM-DD HH:MI:SS AM'),  90);
INSERT INTO changegroup (issueid, created, id) VALUES (23977,  TO_DATE ('2008-09-29 02:44:54 PM', 'YYYY-MM-DD HH:MI:SS AM'),  10);
INSERT INTO changegroup (issueid, created, id) VALUES (23977,  TO_DATE ('2010-05-29 04:47:37 PM', 'YYYY-MM-DD HH:MI:SS AM'),  30);
INSERT INTO changegroup (issueid, created, id) VALUES (23977,  TO_DATE ('2011-02-02 06:14:57 AM', 'YYYY-MM-DD HH:MI:SS AM'),  10);
INSERT INTO changegroup (issueid, created, id) VALUES (23977,  TO_DATE ('2011-02-02 06:15:32 AM', 'YYYY-MM-DD HH:MI:SS AM'),  20);
INSERT INTO changegroup (issueid, created, id) VALUES (23977,  TO_DATE ('2011-02-02 06:15:47 AM', 'YYYY-MM-DD HH:MI:SS AM'),  90);
CREATE TABLE     changeitem
(      groupid          NUMBER
,      newstring     VARCHAR2 (10)
INSERT INTO changeitem (groupid, newstring) VALUES (10, 'Open');
INSERT INTO changeitem (groupid, newstring) VALUES (20, 'Testing');
INSERT INTO changeitem (groupid, newstring) VALUES (30, 'Blocked');
INSERT INTO changeitem (groupid, newstring) VALUES (90, 'Closed');Then post the results you want to get from that data, like this:
ISSUEID HISTORY
  21191 Open (0) >> Testing (692) >> Closed
  23234 Open (45) >> Testing (807) >> Closed
  23977 Open (607) >> Blocked (249) >> Open (0) >> Testing (0) >> ClosedExplain how you get those results from that data. For example:
"The output contains one row per issueid. The HISTORY coloumn shows the different states that the issue went through, in order by created, starting with the earliest one and continuing up until the first 'Closed' state, if there is one. Take the first row, issueid=21191, for example. It started as 'Open' on July 16, 2008, then, on the same day (that is, 0 days later) changed to 'Testing', and then, on June 8, 2010, (692 days later), it became 'Closed'. That same issue opened again later, on September 2, 2010, but I don't want to see any activity after the first 'Closed'."
The database is 10.2.0.4That's very important. Always post your version, like you did.
Here's one way to get those results from that data:
WITH     got_order_row     AS
     SELECT     cg.issueid
     ,     LEAD (cg.created) OVER ( PARTITION BY  cg.issueid
                                      ORDER BY      cg.created
              - cg.created            AS days_in_stage
     ,       ROW_NUMBER ()     OVER ( PARTITION BY  cg.issueid
                                      ORDER BY      cg.created
                           )    AS order_row
     ,     ci.newstring                     AS change_type
     FROM    changegroup     cg
     JOIN     changeitem     ci  ON   cg.id     = ci.groupid
     WHERE     ci.newstring     IN ( 'Blocked'
                       , 'Closed'
                       , 'Testing'
                       , 'Open'
--     AND     ...          -- any other filtering goes here
SELECT       issueid
,       SUBSTR ( SYS_CONNECT_BY_PATH ( change_type || CASE
                                                         WHEN  CONNECT_BY_ISLEAF = 0
                                       THEN  ' ('
                                          || ROUND (days_in_stage)
                                          || ')'
                                                     END
                                , ' >> '
           , 5
           )     AS history
FROM       got_order_row
WHERE       CONNECT_BY_ISLEAF     = 1
START WITH     order_row          = 1
CONNECT BY     order_row          = PRIOR order_row + 1
     AND     issueid               = PRIOR issueid
     AND     PRIOR change_type     != 'Closed'
ORDER BY  issueid
;Combining data from several rows into one big delimited VARCHAR2 column on one row is call String Aggregation .
I hope this answers your question, but I guessed at so many things, I won't be surprised if it doesn't. If that's the case, point out where this is wrong, post what the results should be in those places, and explain how you get those results. Post new data, if necessary.

Similar Messages

  • SQL Help with change multiple columns into a single column

    I am wanting to create either a new View or a new Table based on the following original table:
    Original Table:
    Fiscal Year
    Account
    Budget_Amt_January
    Budget_Amt_February
    Budget_Amt_March
    Budget_Amt_April
    <etc. for each of the 12 months)
    I want the new View or Table to instead be:
    New:
    Fiscal_Year
    Month
    Account
    Budget_Amount
    I can't simply drop the original table, it will have to always exist since it is part of the Finance package, but for ease of reporting against I am wanting to create this new View.
    Any ideas on how to go about this?
    Thanks!

    I had to do something very similar just this week - in my case a record read from a csv into a table, then needs loading into a destination table, and the rows are columns in the csv. I went for INSERT ALL as I also had some conditions.
      INSERT ALL
        WHEN low1 != -998 OR high1 != -998 THEN
        INTO partial_profile_temp (search_id, locus_id, low_allele, high_allele)
        VALUES ( search_id, 1, low1, high1 )
        WHEN low2 != -998 OR high2 != -998 THEN
        INTO partial_profile_temp (search_id, locus_id, low_allele, high_allele)
        VALUES ( search_id, 2, low2, high2 )
        WHEN low5 != -998 OR high5 != -998 THEN
        INTO partial_profile_temp (search_id, locus_id, low_allele, high_allele)
        VALUES ( search_id, 5, low5, high5 )
        WHEN low6 != -998 OR high6 != -998 THEN
        INTO partial_profile_temp (search_id, locus_id, low_allele, high_allele)
        VALUES ( search_id, 6, low6, high6 )
        WHEN low7 != -998 OR high7 != -998 THEN
        INTO partial_profile_temp (search_id, locus_id, low_allele, high_allele)
        VALUES ( search_id, 7, low7, high7 )
        WHEN low8 != -998 OR high8 != -998 THEN
        INTO partial_profile_temp (search_id, locus_id, low_allele, high_allele)
        VALUES ( search_id, 8, low8, high8 )
        WHEN low9 != -998 OR high9 != -998 THEN
        INTO partial_profile_temp (search_id, locus_id, low_allele, high_allele)
        VALUES ( search_id, 9, low9, high9 )
        WHEN low10 != -998 OR high10 != -998 THEN
        INTO partial_profile_temp (search_id, locus_id, low_allele, high_allele)
        VALUES ( search_id, 10, low10, high10 )
        WHEN low11 != -998 OR high11 != -998 THEN
        INTO partial_profile_temp (search_id, locus_id, low_allele, high_allele)
        VALUES ( search_id, 11, low11, high11 )
        WHEN low12 != -998 OR high12 != -998 THEN
        INTO partial_profile_temp (search_id, locus_id, low_allele, high_allele)
        VALUES ( search_id, 12, low12, high12 )
        WHEN low13 != -998 OR high13 != -998 THEN
        INTO partial_profile_temp (search_id, locus_id, low_allele, high_allele)
        VALUES ( search_id, 13, low13, high13 )
        SELECT * FROM bulk_search_load bst, partial_details_temp pdt
        WHERE id = case_number -- only retrieves details for those records that are found in bulk_search_load
        AND filename like 'NETH\_%' escape '\'
        AND processed = 'N'; 

  • Merging two rows into a single row

    Hi ,
    I wish to merge few columns of tow rows into a single row.
    if i use union it gives two rows as o/p.
    What is the exact sql statement for that?
    Thanks

    Hi Sridhar,
    This is my code for merging and i used union.
    Suggest me good solution.
    CREATE OR REPLACE VIEW INSPECTINT.INSPECT_LOC_TRACKING_RPT_VIEW AS
    SELECT
    VEN_COMPANY_NAME VEN_COMPANY_NAME,
    VEN_COMPANY_NAME_2 VEN_COMPANY_NAME_2,
    VEN_CONTACT_FIRST_NAME VEN_CONTACT_FIRST_NAME,
    VEN_CONTACT_MIDDLE_NAME VEN_CONTACT_MIDDLE_NAME,
    VEN_CONTACT_LAST_NAME VEN_CONTACT_LAST_NAME,
    VEN_ADDRESS_LINE_1 VEN_ADDRESS_LINE_1,
    VEN_ADDRESS_LINE_2 VEN_ADDRESS_LINE_2,
    VEN_CITY VEN_CITY,
    VEN_CNT_COUNTY_CODE VEN_CNT_COUNTY_CODE,
    VEN_STC_STATE_CODE VEN_STC_STATE_CODE,
    VEN_ZIP_CODE VEN_ZIP_CODE,
    VEN_PHONE_NO_1 VEN_PHONE_NO_1,
    VEN_PHONE_EXTN_1 VEN_PHONE_EXTN_1,
    VEN_PHONE_NO_2 VEN_PHONE_NO_2,
    VEN_PHONE_EXTN_2 VEN_PHONE_EXTN_2,
    VEN_FAX_NO_1 VEN_FAX_NO_1,
    VEN_VENDOR_NO VEN_VENDOR_NO,
    VEN_APV_AP_VENDOR_ID VEN_APV_AP_VENDOR_ID,
    VEN_EMAIL_ADDRESS VEN_EMAIL_ADDRESS,
    --all these should be null
    to_number(NULL) PHY_LCN_PARAMETER_ID,
    to_char(NULL) PHY_LCN_CURRENT_ADDRESS_IND,
    to_char(NULL) PHY_LCN_STATUS_CODE,
    to_char(NULL) PHY_LCN_LTY_LOCATION_TYPE,
    to_char(NULL) PHY_LCN_ADT_ADDRESS_TYPE,
    to_char(NULL) PHY_LCN_HOUSE_NO,
    to_char(NULL) PHY_LCN_ADDRESS_LINE_1,
    to_char(NULL) PHY_LCN_ADDRESS_LINE_2,
    to_char(NULL) PHY_LCN_CITY,
    to_char(NULL) PHY_LCN_STC_STATE_CODE,
    to_char(NULL) PHY_LCN_ZIP_CODE,
    to_char(NULL) PHY_LCN_CNT_COUNTY_CODE,
    to_date(NULL) PHY_END_DATE,
    to_number(NULL) PHY_LCN_VEN_VENDOR_ID_GTA,
    to_char(NULL) PHY_LCN_SUB_LOCATION_GTA,
    to_char(NULL) PHY_LCN_DIRECTION_GTA,
    ---all these should be null
    to_char(NULL) LOW_LCN_PARAMETER_ID,
    to_char(NULL) LOW_LCN_CURRENT_ADDRESS_IND,
    to_char(NULL) LOW_LCN_STATUS_CODE,
    to_char(NULL) LOW_LCN_LTY_LOCATION_TYPE,
    to_char(NULL) LOW_LCN_ADT_ADDRESS_TYPE,
    to_char(NULL) LOW_LCN_HOUSE_NO,
    to_char(NULL) LOW_LCN_ADDRESS_LINE_1,
    to_char(NULL) LOW_LCN_ADDRESS_LINE_2,
    to_char(NULL) LOW_LCN_CITY,
    to_char(NULL) LOW_LCN_STC_STATE_CODE,
    to_char(NULL) LOW_LCN_ZIP_CODE,
    to_char(NULL) LOW_LCN_CNT_COUNTY_CODE,
    to_char(NULL) LOW_LCN_LANDLORD,
    to_number(NULL) LOW_LCN_LANDLORD_PHONE,
    to_date(NULL) LOW_END_DATE,
    to_char(NULL) LOW_LCN_SUB_LOCATION_GTA,
    to_char(NULL) LOW_LCN_DIRECTION_GTA
    FROM LOCATIONS LOC , VENDORS VEN
    WHERE LOC.LCN_VEN_VENDOR_ID_GTA IS NOT NULL
    AND LOC.LCN_VEN_VENDOR_ID_GTA = VEN_VENDOR_ID
    AND LOC.LCN_LTY_LOCATION_TYPE ='AS'
    UNION ALL
    SELECT
    to_char(NULL) VEN_COMPANY_NAME,
    to_char(NULL) VEN_COMPANY_NAME_2,
    to_char(NULL) VEN_CONTACT_FIRST_NAME,
    to_char(NULL) VEN_CONTACT_MIDDLE_NAME,
    to_char(NULL) VEN_CONTACT_LAST_NAME,
    to_char(NULL) VEN_ADDRESS_LINE_1,
    to_char(NULL) VEN_ADDRESS_LINE_2,
    to_char(NULL) VEN_CITY,
    to_char(NULL) VEN_CNT_COUNTY_CODE,
    to_char(NULL) VEN_STC_STATE_CODE,
    to_char(NULL) VEN_ZIP_CODE,
    to_number(NULL) VEN_PHONE_NO_1,
    to_number(NULL) VEN_PHONE_EXTN_1,
    to_number(NULL) VEN_PHONE_NO_2,
    to_number(NULL) VEN_PHONE_EXTN_2,
    to_number(NULL) VEN_FAX_NO_1,
    to_char(NULL) VEN_VENDOR_NO,
    to_char(NULL) VEN_APV_AP_VENDOR_ID,
    to_char(NULL) VEN_EMAIL_ADDRESS,
    decode(lcn_adt_address_type,'P',to_number(LCN_PARAMETER_ID),to_number(NULL)) PHY_LCN_PARAMETER_ID,
    decode(lcn_adt_address_type,'P',LCN_CURRENT_ADDRESS_IND,to_char(NULL)) PHY_LCN_CURRENT_ADDRESS_IND,
    decode(lcn_adt_address_type,'P',LCN_STATUS_CODE,to_char(NULL)) PHY_LCN_STATUS_CODE,
    decode(lcn_adt_address_type,'P',LCN_STATUS_CODE,to_char(NULL)) PHY_LCN_LTY_LOCATION_TYPE,
    decode(lcn_adt_address_type,'P',LCN_ADT_ADDRESS_TYPE,to_char(NULL)) PHY_LCN_ADT_ADDRESS_TYPE,
    decode(lcn_adt_address_type,'P',LCN_HOUSE_NO,to_char(NULL)) PHY_LCN_HOUSE_NO,
    decode(lcn_adt_address_type,'P',LCN_ADDRESS_LINE_1,to_char(NULL)) PHY_LCN_ADDRESS_LINE_1,
    decode(lcn_adt_address_type,'P',LCN_ADDRESS_LINE_2,to_char(NULL)) PHY_LCN_ADDRESS_LINE_2,
    decode(lcn_adt_address_type,'P',LCN_CITY,to_char(NULL)) PHY_LCN_CITY,
    decode(lcn_adt_address_type,'P',LCN_STC_STATE_CODE,to_char(NULL)) PHY_LCN_STC_STATE_CODE,
    decode(lcn_adt_address_type,'P',LCN_ZIP_CODE,to_char(NULL)) PHY_LCN_ZIP_CODE,
    decode(lcn_adt_address_type,'P',LCN_CNT_COUNTY_CODE,to_char(NULL)) PHY_LCN_CNT_COUNTY_CODE,
    decode(lcn_adt_address_type,'P',END_DATE,to_char(NULL)) PHY_END_DATE,
    decode(lcn_adt_address_type,'P',LCN_VEN_VENDOR_ID_GTA,to_char(NULL)) PHY_LCN_VEN_VENDOR_ID_GTA,
    decode(lcn_adt_address_type,'P',LCN_SUB_LOCATION_GTA,to_char(NULL)) PHY_LCN_SUB_LOCATION_GTA,
    decode(lcn_adt_address_type,'P',LCN_DIRECTION_GTA,to_char(NULL)) PHY_LCN_DIRECTION_GTA,
    decode(LCN_ADT_ADDRESS_TYPE,'D',LCN_PARAMETER_ID,to_char(NULL)) LOW_LCN_PARAMETER_ID,
    decode(LCN_ADT_ADDRESS_TYPE,'D',LCN_CURRENT_ADDRESS_IND,to_char(NULL)) LOW_LCN_CURRENT_ADDRESS_IND,
    decode(LCN_ADT_ADDRESS_TYPE,'D',LCN_STATUS_CODE,to_char(NULL)) LOW_LCN_STATUS_CODE,
    decode(LCN_ADT_ADDRESS_TYPE,'D',LCN_LTY_LOCATION_TYPE,to_char(NULL)) LOW_LCN_LTY_LOCATION_TYPE,
    decode(LCN_ADT_ADDRESS_TYPE,'D',LCN_ADT_ADDRESS_TYPE,to_char(NULL)) LOW_LCN_ADT_ADDRESS_TYPE,
    decode(LCN_ADT_ADDRESS_TYPE,'D',LCN_HOUSE_NO,to_char(NULL)) LOW_LCN_HOUSE_NO,
    decode(LCN_ADT_ADDRESS_TYPE,'D',LCN_ADDRESS_LINE_1,to_char(NULL)) LOW_LCN_ADDRESS_LINE_1,
    decode(LCN_ADT_ADDRESS_TYPE,'D',LCN_ADDRESS_LINE_2,to_char(NULL)) LOW_LCN_ADDRESS_LINE_2,
    decode(LCN_ADT_ADDRESS_TYPE,'D',LCN_CITY,to_char(NULL)) LOW_LCN_CITY,
    decode(LCN_ADT_ADDRESS_TYPE,'D',LCN_STC_STATE_CODE,to_char(NULL)) LOW_LCN_STC_STATE_CODE,
    decode(LCN_ADT_ADDRESS_TYPE,'D',LCN_ZIP_CODE,to_char(NULL)) LOW_LCN_ZIP_CODE,
    decode(LCN_ADT_ADDRESS_TYPE,'D',LCN_CNT_COUNTY_CODE,to_char(NULL)) LOW_LCN_CNT_COUNTY_CODE,
    decode(LCN_ADT_ADDRESS_TYPE,'D',LCN_LANDLORD,to_char(NULL)) LOW_LCN_LANDLORD,
    decode(LCN_ADT_ADDRESS_TYPE,'D',LCN_LANDLORD_PHONE,to_char(NULL)) LOW_LCN_LANDLORD_PHONE,
    decode(LCN_ADT_ADDRESS_TYPE,'D',END_DATE,to_char(NULL)) LOW_END_DATE,
    decode(LCN_ADT_ADDRESS_TYPE,'D',LCN_SUB_LOCATION_GTA,to_char(NULL)) LOW_LCN_SUB_LOCATION_GTA,
    decode(LCN_ADT_ADDRESS_TYPE,'D',LCN_DIRECTION_GTA,to_char(NULL)) LOW_LCN_DIRECTION_GTA
    FROM LOCATIONS LOC
    WHERE (LCN_LTY_LOCATION_TYPE ='AS' OR LCN_ADT_ADDRESS_TYPE='D')
    AND LCN_CURRENT_ADDRESS_IND ='Y'
    thanks

  • Oracle query - Merging multiple rows into a single row output

    Hi All,
    I have to have a multiple row output to be converted into a single row output.My current output looks as follows:
    ID YR INC_CODE OFFN SCHOOLNO
    8006 2002 00175 SC03 12
    8006 2002 00175 DC06 12
    8006 2002 00175 DC03 12
    8006 2002 00175 DC02 12
    ID,INCIDENT CODE,OFFENSE are all Primary keys
    So I need the output as follows:(IN ONE ROW)
    ID YR INC_CODE OFFN1 OFFN2 OFFN3 OFFN4 SCHOOLNO
    8006 2002 00175 SC03 DC06 DC03 DC02 12
    Can you help me on this since have been spinning the wheel and this has to be a query since will have couple of tables join to produce a materialized view.
    Thanks in advance

    Hi Nigel,
    Thanks for the reply I tested out the portion having the decode and I get the output as follows:
    ID YR INC_CODE OFFN1 OFFN2 OFFN3 OFFN4 OFFN5
    8982 2002 2175 DOC01 -----------------------
    8982 2002 2175 DOC02-------------------
    8982 2002 2175 DOC03------------
    8982 2002 2175 DOC06-------
    8982 2002 2175 SCV03
    There is no value as max for OFFN and each INC_CODE MAY HAVE UP TO A MAX OF 5 OFFN.My query is as follows:
    select distinct STU_STUDENT_ID, INC_BEG_SCH_YR,INC_INCIDENT_CODE
    , decode(rank() over (partition by INC_CODE order by OFFN),1,OFFN,null) as offn1
    , decode(rank() over (partition by INC_CODE order by OFFN),2,OFFN,null) as offn2
    , decode(rank() over (partition by INC_CODE order by OFFN),3,OFFN,null) as offn3
    , decode(rank() over (partition by INC_CODE order by OFFN),4,OFFN,null) as offn4
    , decode(rank() over (partition by INC_CODE order by OFFN),5,OFFN,null) as offn5
    from stu_offn where
    stu_offn.ID = '8982' and stu_offn.INC_CODE = '2175'
    (****Where clause is just given to just check a value)
    So as you know I need to just have all the OFFN in a single row ie as follows:
    ID YR INC_CODE OFFN1 OFFN2 OFFN3 OFFN4 OFFN5
    8982 2002 2175 DOC01 DOC02 DOC03 DOC06 SCV03
    Can you just give me a step by step procedure to go through this and the table in this case is just 'STU_OFFN'
    Thanks for the earlier reply appreciate it!
    ****Sending this again to show the exact way the output is coming

  • Flatten rows into a single row

    Hi All,
    I have a table1 with records and PK for table 1 is (Date,Time).
    All I have to do is for a particular transaction, I have to get all the records and flatten them into a single row.
    For ex: Table 1 has the following
    Date Time Col1 Value
    08/03/2010 10:00am Employee_name John
    08/03/2010 10:00am Employee_ID 20
    08/03/2010 10:00am Salary 10000
    Now I have a table 2 which has the following structure:
    Date Time Employee_name Employee_ID Salary
    08/03/2010 10:00am John 20 10000
    Please let me know how to achieve this.,
    Thank You.

    Hi,
    Are you saying that you want to create table2, given table1?
    Displaying one column from many rows as if they were many columns on one row is called a Pivot , and here's one way to do it:
    SELECT       date_time
    ,       MIN (CASE WHEN col1 = 'Employee_name' THEN value END)     AS employee_name
    ,       MIN (CASE WHEN col1 = 'Employee_ID'      THEN value END)     AS employee_id
    ,       MIN (CASE WHEN col1 = 'Salary'      THEN value END)     AS salary
    FROM       table1
    GROUP BY  date_time
    ;Whenever you have a question, say what version of Oracle you're using.
    The query above works in Oracle 8.1 and up, but it might be simpler using the SELECT ... PIVOT feature that was introduced in Oracle 11.
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements), and also post the results you want from that data.

  • Merging Multiple Rows into a single Row

    I've read a number of posts with no real good answers or answers that might be good for tables with 3 columns of data. I have a table with 33 columns that will all need to be combined. A little history. Apparently in production the Primary Key Constraint
    was dropped which allowed some duplicate data into the table. Now they want me to squish the records together to fix it.
    Sorry I couldn't include the screen shot of the data, MSDN says my account isn't verified...
    My requirements when I'm putting them together, CERElibilityID is a unique column. This is a sticky problem because in the related tables it is only one of the parent records gets child records related to it.
     I just want to keep the one that has the child records in CERPrepActivity table. If there are no child records then the rule will be like all the other records with data. 
    If a  field is null and another record has data we take the record that has data.
    If multiple records have data we take the record that has the highest "ModifiedOn" timestamp column value.
    I feel like I'm asking a lot, but I'm in a bit of a bind and I've spent the morning Googling and have come up with nothing 
    Thank  you for any help the community can provide and the more specific you can be the better. I'm not a DBA or SQL guru by any stretch so I'm way out of my element.
    Thanks

    Using the systables, you can get information about your table. I put these together:
    SELECT '
    LEFT OUTER JOIN #CEREligibility ['+c.name+']
    ON s.caseID = ['+c.name+'].caseID
    AND s.modifiedOn = ['+c.name+'].modifiedOn
    AND ['+c.name+'].['+c.name+'] = (SELECT TOP 1 ['+c.name+'] FROM #CEREligibility WHERE caseID = s.caseID AND ['+c.name+'] IS NOT NULL ORDER BY ModifiedOn)
    AND ['+c.name+'].['+c.name+'] IS NOT NULL'
    FROM tempdb.sys.objects o
    INNER JOIN tempdb.sys.columns c
    ON o.object_id = c.object_id
    AND o.name LIKE '#CEREligibility%'
    SELECT '['+c.name+'].['+c.name+'] AS ['+c.name+'], '
    FROM tempdb.sys.objects o
    INNER JOIN tempdb.sys.columns c
    ON o.object_id = c.object_id
    AND o.name LIKE '#CEREligibility%'
    On my test system I created your table as a temp table named #CEREligibility.
    The first of these two queries generates LEFT OUT JOIN SQL for a self join. Because we're using the columns systable, a LOJ for each column is generated.
    The second, produces a select list.
    Putting the two together like so, and adding a FROM and GROUP BY gives us:
    SELECT
    MAX([CEREligibilityId].[CEREligibilityId]) AS [CEREligibilityId], s.[CaseId], MAX([M2Eligibility].[M2Eligibility]) AS [M2Eligibility], MAX([CDREligibility].[CDREligibility]) AS [CDREligibility], MAX([M2Comments].[M2Comments]) AS [M2Comments], MAX([M2CommentsRtf].[M2CommentsRtf]) AS [M2CommentsRtf], MAX([CDRComments].[CDRComments]) AS [CDRComments], MAX([CDRCommentsRtf].[CDRCommentsRtf]) AS [CDRCommentsRtf], MAX([RIAWA].[RIAWA]) AS [RIAWA], MAX([RIAWADate].[RIAWADate]) AS [RIAWADate], MAX([EducationAndTraining].[EducationAndTraining]) AS [EducationAndTraining], MAX([EducationAndTrainingDate].[EducationAndTrainingDate]) AS [EducationAndTrainingDate], MAX([Internship].[Internship]) AS [Internship], MAX([InternshipDate].[InternshipDate]) AS [InternshipDate], MAX([Apprenticeship].[Apprenticeship]) AS [Apprenticeship], MAX([ApprenticeshipDate].[ApprenticeshipDate]) AS [ApprenticeshipDate], MAX([Entrepreneurship].[Entrepreneurship]) AS [Entrepreneurship], MAX([EntrepreneurshipDate].[EntrepreneurshipDate]) AS [EntrepreneurshipDate], MAX([EmploymentPrep].[EmploymentPrep]) AS [EmploymentPrep], MAX([EmploymentPrepDate].[EmploymentPrepDate]) AS [EmploymentPrepDate], MAX([OTPrep].[OTPrep]) AS [OTPrep], MAX([OTPrepDate].[OTPrepDate]) AS [OTPrepDate], MAX([ExitInterview].[ExitInterview]) AS [ExitInterview], MAX([ExitInterviewDate].[ExitInterviewDate]) AS [ExitInterviewDate], MAX([CreatedOn].[CreatedOn]) AS [CreatedOn], MAX([CreatedBy].[CreatedBy]) AS [CreatedBy], MAX([ModifiedOn].[ModifiedOn]) AS [ModifiedOn], MAX([ModifiedBy].[ModifiedBy]) AS [ModifiedBy], MAX([BCPermInEligibility].[BCPermInEligibility]) AS [BCPermInEligibility], MAX([CCPermInEligibility].[CCPermInEligibility]) AS [CCPermInEligibility], MAX([M2EligibilityDate].[M2EligibilityDate]) AS [M2EligibilityDate], MAX([CDREligibilityDate].[CDREligibilityDate]) AS [CDREligibilityDate], MAX([ExitSeparationCode].[ExitSeparationCode]) AS [ExitSeparationCode], MAX([ExitSeparationSubCode].[ExitSeparationSubCode]) AS [ExitSeparationSubCode]
    FROM #CEREligibility s
    LEFT OUTER JOIN #CEREligibility [CEREligibilityId]
    ON s.caseID = [CEREligibilityId].caseID
    AND s.modifiedOn = [CEREligibilityId].modifiedOn
    AND [CEREligibilityId].[CEREligibilityId] = (SELECT TOP 1 [CEREligibilityId] FROM #CEREligibility WHERE caseID = s.caseID AND [CEREligibilityId] IS NOT NULL ORDER BY ModifiedOn)
    AND [CEREligibilityId].[CEREligibilityId] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [CaseId]
    ON s.caseID = [CaseId].caseID
    AND s.modifiedOn = [CaseId].modifiedOn
    AND [CaseId].[CaseId] = (SELECT TOP 1 [CaseId] FROM #CEREligibility WHERE caseID = s.caseID AND [CaseId] IS NOT NULL ORDER BY ModifiedOn)
    AND [CaseId].[CaseId] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [M2Eligibility]
    ON s.caseID = [M2Eligibility].caseID
    AND s.modifiedOn = [M2Eligibility].modifiedOn
    AND [M2Eligibility].[M2Eligibility] = (SELECT TOP 1 [M2Eligibility] FROM #CEREligibility WHERE caseID = s.caseID AND [M2Eligibility] IS NOT NULL ORDER BY ModifiedOn)
    AND [M2Eligibility].[M2Eligibility] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [CDREligibility]
    ON s.caseID = [CDREligibility].caseID
    AND s.modifiedOn = [CDREligibility].modifiedOn
    AND [CDREligibility].[CDREligibility] = (SELECT TOP 1 [CDREligibility] FROM #CEREligibility WHERE caseID = s.caseID AND [CDREligibility] IS NOT NULL ORDER BY ModifiedOn)
    AND [CDREligibility].[CDREligibility] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [M2Comments]
    ON s.caseID = [M2Comments].caseID
    AND s.modifiedOn = [M2Comments].modifiedOn
    AND [M2Comments].[M2Comments] = (SELECT TOP 1 [M2Comments] FROM #CEREligibility WHERE caseID = s.caseID AND [M2Comments] IS NOT NULL ORDER BY ModifiedOn)
    AND [M2Comments].[M2Comments] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [M2CommentsRtf]
    ON s.caseID = [M2CommentsRtf].caseID
    AND s.modifiedOn = [M2CommentsRtf].modifiedOn
    AND [M2CommentsRtf].[M2CommentsRtf] = (SELECT TOP 1 [M2CommentsRtf] FROM #CEREligibility WHERE caseID = s.caseID AND [M2CommentsRtf] IS NOT NULL ORDER BY ModifiedOn)
    AND [M2CommentsRtf].[M2CommentsRtf] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [CDRComments]
    ON s.caseID = [CDRComments].caseID
    AND s.modifiedOn = [CDRComments].modifiedOn
    AND [CDRComments].[CDRComments] = (SELECT TOP 1 [CDRComments] FROM #CEREligibility WHERE caseID = s.caseID AND [CDRComments] IS NOT NULL ORDER BY ModifiedOn)
    AND [CDRComments].[CDRComments] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [CDRCommentsRtf]
    ON s.caseID = [CDRCommentsRtf].caseID
    AND s.modifiedOn = [CDRCommentsRtf].modifiedOn
    AND [CDRCommentsRtf].[CDRCommentsRtf] = (SELECT TOP 1 [CDRCommentsRtf] FROM #CEREligibility WHERE caseID = s.caseID AND [CDRCommentsRtf] IS NOT NULL ORDER BY ModifiedOn)
    AND [CDRCommentsRtf].[CDRCommentsRtf] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [RIAWA]
    ON s.caseID = [RIAWA].caseID
    AND s.modifiedOn = [RIAWA].modifiedOn
    AND [RIAWA].[RIAWA] = (SELECT TOP 1 [RIAWA] FROM #CEREligibility WHERE caseID = s.caseID AND [RIAWA] IS NOT NULL ORDER BY ModifiedOn)
    AND [RIAWA].[RIAWA] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [RIAWADate]
    ON s.caseID = [RIAWADate].caseID
    AND s.modifiedOn = [RIAWADate].modifiedOn
    AND [RIAWADate].[RIAWADate] = (SELECT TOP 1 [RIAWADate] FROM #CEREligibility WHERE caseID = s.caseID AND [RIAWADate] IS NOT NULL ORDER BY ModifiedOn)
    AND [RIAWADate].[RIAWADate] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [EducationAndTraining]
    ON s.caseID = [EducationAndTraining].caseID
    AND s.modifiedOn = [EducationAndTraining].modifiedOn
    AND [EducationAndTraining].[EducationAndTraining] = (SELECT TOP 1 [EducationAndTraining] FROM #CEREligibility WHERE caseID = s.caseID AND [EducationAndTraining] IS NOT NULL ORDER BY ModifiedOn)
    AND [EducationAndTraining].[EducationAndTraining] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [EducationAndTrainingDate]
    ON s.caseID = [EducationAndTrainingDate].caseID
    AND s.modifiedOn = [EducationAndTrainingDate].modifiedOn
    AND [EducationAndTrainingDate].[EducationAndTrainingDate] = (SELECT TOP 1 [EducationAndTrainingDate] FROM #CEREligibility WHERE caseID = s.caseID AND [EducationAndTrainingDate] IS NOT NULL ORDER BY ModifiedOn)
    AND [EducationAndTrainingDate].[EducationAndTrainingDate] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [Internship]
    ON s.caseID = [Internship].caseID
    AND s.modifiedOn = [Internship].modifiedOn
    AND [Internship].[Internship] = (SELECT TOP 1 [Internship] FROM #CEREligibility WHERE caseID = s.caseID AND [Internship] IS NOT NULL ORDER BY ModifiedOn)
    AND [Internship].[Internship] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [InternshipDate]
    ON s.caseID = [InternshipDate].caseID
    AND s.modifiedOn = [InternshipDate].modifiedOn
    AND [InternshipDate].[InternshipDate] = (SELECT TOP 1 [InternshipDate] FROM #CEREligibility WHERE caseID = s.caseID AND [InternshipDate] IS NOT NULL ORDER BY ModifiedOn)
    AND [InternshipDate].[InternshipDate] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [Apprenticeship]
    ON s.caseID = [Apprenticeship].caseID
    AND s.modifiedOn = [Apprenticeship].modifiedOn
    AND [Apprenticeship].[Apprenticeship] = (SELECT TOP 1 [Apprenticeship] FROM #CEREligibility WHERE caseID = s.caseID AND [Apprenticeship] IS NOT NULL ORDER BY ModifiedOn)
    AND [Apprenticeship].[Apprenticeship] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [ApprenticeshipDate]
    ON s.caseID = [ApprenticeshipDate].caseID
    AND s.modifiedOn = [ApprenticeshipDate].modifiedOn
    AND [ApprenticeshipDate].[ApprenticeshipDate] = (SELECT TOP 1 [ApprenticeshipDate] FROM #CEREligibility WHERE caseID = s.caseID AND [ApprenticeshipDate] IS NOT NULL ORDER BY ModifiedOn)
    AND [ApprenticeshipDate].[ApprenticeshipDate] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [Entrepreneurship]
    ON s.caseID = [Entrepreneurship].caseID
    AND s.modifiedOn = [Entrepreneurship].modifiedOn
    AND [Entrepreneurship].[Entrepreneurship] = (SELECT TOP 1 [Entrepreneurship] FROM #CEREligibility WHERE caseID = s.caseID AND [Entrepreneurship] IS NOT NULL ORDER BY ModifiedOn)
    AND [Entrepreneurship].[Entrepreneurship] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [EntrepreneurshipDate]
    ON s.caseID = [EntrepreneurshipDate].caseID
    AND s.modifiedOn = [EntrepreneurshipDate].modifiedOn
    AND [EntrepreneurshipDate].[EntrepreneurshipDate] = (SELECT TOP 1 [EntrepreneurshipDate] FROM #CEREligibility WHERE caseID = s.caseID AND [EntrepreneurshipDate] IS NOT NULL ORDER BY ModifiedOn)
    AND [EntrepreneurshipDate].[EntrepreneurshipDate] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [EmploymentPrep]
    ON s.caseID = [EmploymentPrep].caseID
    AND s.modifiedOn = [EmploymentPrep].modifiedOn
    AND [EmploymentPrep].[EmploymentPrep] = (SELECT TOP 1 [EmploymentPrep] FROM #CEREligibility WHERE caseID = s.caseID AND [EmploymentPrep] IS NOT NULL ORDER BY ModifiedOn)
    AND [EmploymentPrep].[EmploymentPrep] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [EmploymentPrepDate]
    ON s.caseID = [EmploymentPrepDate].caseID
    AND s.modifiedOn = [EmploymentPrepDate].modifiedOn
    AND [EmploymentPrepDate].[EmploymentPrepDate] = (SELECT TOP 1 [EmploymentPrepDate] FROM #CEREligibility WHERE caseID = s.caseID AND [EmploymentPrepDate] IS NOT NULL ORDER BY ModifiedOn)
    AND [EmploymentPrepDate].[EmploymentPrepDate] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [OTPrep]
    ON s.caseID = [OTPrep].caseID
    AND s.modifiedOn = [OTPrep].modifiedOn
    AND [OTPrep].[OTPrep] = (SELECT TOP 1 [OTPrep] FROM #CEREligibility WHERE caseID = s.caseID AND [OTPrep] IS NOT NULL ORDER BY ModifiedOn)
    AND [OTPrep].[OTPrep] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [OTPrepDate]
    ON s.caseID = [OTPrepDate].caseID
    AND s.modifiedOn = [OTPrepDate].modifiedOn
    AND [OTPrepDate].[OTPrepDate] = (SELECT TOP 1 [OTPrepDate] FROM #CEREligibility WHERE caseID = s.caseID AND [OTPrepDate] IS NOT NULL ORDER BY ModifiedOn)
    AND [OTPrepDate].[OTPrepDate] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [ExitInterview]
    ON s.caseID = [ExitInterview].caseID
    AND s.modifiedOn = [ExitInterview].modifiedOn
    AND [ExitInterview].[ExitInterview] = (SELECT TOP 1 [ExitInterview] FROM #CEREligibility WHERE caseID = s.caseID AND [ExitInterview] IS NOT NULL ORDER BY ModifiedOn)
    AND [ExitInterview].[ExitInterview] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [ExitInterviewDate]
    ON s.caseID = [ExitInterviewDate].caseID
    AND s.modifiedOn = [ExitInterviewDate].modifiedOn
    AND [ExitInterviewDate].[ExitInterviewDate] = (SELECT TOP 1 [ExitInterviewDate] FROM #CEREligibility WHERE caseID = s.caseID AND [ExitInterviewDate] IS NOT NULL ORDER BY ModifiedOn)
    AND [ExitInterviewDate].[ExitInterviewDate] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [CreatedOn]
    ON s.caseID = [CreatedOn].caseID
    AND s.modifiedOn = [CreatedOn].modifiedOn
    AND [CreatedOn].[CreatedOn] = (SELECT TOP 1 [CreatedOn] FROM #CEREligibility WHERE caseID = s.caseID AND [CreatedOn] IS NOT NULL ORDER BY ModifiedOn)
    AND [CreatedOn].[CreatedOn] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [CreatedBy]
    ON s.caseID = [CreatedBy].caseID
    AND s.modifiedOn = [CreatedBy].modifiedOn
    AND [CreatedBy].[CreatedBy] = (SELECT TOP 1 [CreatedBy] FROM #CEREligibility WHERE caseID = s.caseID AND [CreatedBy] IS NOT NULL ORDER BY ModifiedOn)
    AND [CreatedBy].[CreatedBy] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [ModifiedOn]
    ON s.caseID = [ModifiedOn].caseID
    AND s.modifiedOn = [ModifiedOn].modifiedOn
    AND [ModifiedOn].[ModifiedOn] = (SELECT TOP 1 [ModifiedOn] FROM #CEREligibility WHERE caseID = s.caseID AND [ModifiedOn] IS NOT NULL ORDER BY ModifiedOn)
    AND [ModifiedOn].[ModifiedOn] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [ModifiedBy]
    ON s.caseID = [ModifiedBy].caseID
    AND s.modifiedOn = [ModifiedBy].modifiedOn
    AND [ModifiedBy].[ModifiedBy] = (SELECT TOP 1 [ModifiedBy] FROM #CEREligibility WHERE caseID = s.caseID AND [ModifiedBy] IS NOT NULL ORDER BY ModifiedOn)
    AND [ModifiedBy].[ModifiedBy] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [BCPermInEligibility]
    ON s.caseID = [BCPermInEligibility].caseID
    AND s.modifiedOn = [BCPermInEligibility].modifiedOn
    AND [BCPermInEligibility].[BCPermInEligibility] = (SELECT TOP 1 [BCPermInEligibility] FROM #CEREligibility WHERE caseID = s.caseID AND [BCPermInEligibility] IS NOT NULL ORDER BY ModifiedOn)
    AND [BCPermInEligibility].[BCPermInEligibility] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [CCPermInEligibility]
    ON s.caseID = [CCPermInEligibility].caseID
    AND s.modifiedOn = [CCPermInEligibility].modifiedOn
    AND [CCPermInEligibility].[CCPermInEligibility] = (SELECT TOP 1 [CCPermInEligibility] FROM #CEREligibility WHERE caseID = s.caseID AND [CCPermInEligibility] IS NOT NULL ORDER BY ModifiedOn)
    AND [CCPermInEligibility].[CCPermInEligibility] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [M2EligibilityDate]
    ON s.caseID = [M2EligibilityDate].caseID
    AND s.modifiedOn = [M2EligibilityDate].modifiedOn
    AND [M2EligibilityDate].[M2EligibilityDate] = (SELECT TOP 1 [M2EligibilityDate] FROM #CEREligibility WHERE caseID = s.caseID AND [M2EligibilityDate] IS NOT NULL ORDER BY ModifiedOn)
    AND [M2EligibilityDate].[M2EligibilityDate] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [CDREligibilityDate]
    ON s.caseID = [CDREligibilityDate].caseID
    AND s.modifiedOn = [CDREligibilityDate].modifiedOn
    AND [CDREligibilityDate].[CDREligibilityDate] = (SELECT TOP 1 [CDREligibilityDate] FROM #CEREligibility WHERE caseID = s.caseID AND [CDREligibilityDate] IS NOT NULL ORDER BY ModifiedOn)
    AND [CDREligibilityDate].[CDREligibilityDate] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [ExitSeparationCode]
    ON s.caseID = [ExitSeparationCode].caseID
    AND s.modifiedOn = [ExitSeparationCode].modifiedOn
    AND [ExitSeparationCode].[ExitSeparationCode] = (SELECT TOP 1 [ExitSeparationCode] FROM #CEREligibility WHERE caseID = s.caseID AND [ExitSeparationCode] IS NOT NULL ORDER BY ModifiedOn)
    AND [ExitSeparationCode].[ExitSeparationCode] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [ExitSeparationSubCode]
    ON s.caseID = [ExitSeparationSubCode].caseID
    AND s.modifiedOn = [ExitSeparationSubCode].modifiedOn
    AND [ExitSeparationSubCode].[ExitSeparationSubCode] = (SELECT TOP 1 [ExitSeparationSubCode] FROM #CEREligibility WHERE caseID = s.caseID AND [ExitSeparationSubCode] IS NOT NULL ORDER BY ModifiedOn)
    AND [ExitSeparationSubCode].[ExitSeparationSubCode] IS NOT NULL
    GROUP BY s.caseID
    When I ran this against your test data, It produced a single row for each of the two case ID's.
    To keep performance in line, I also created a covering index on the temp table:
    CREATE INDEX idx_caseID_ModifiedOn ON #CEREligibility (caseID, modifiedOn) INCLUDE ([CEREligibilityId], [M2Eligibility], [CDREligibility], [M2Comments], [M2CommentsRtf], [CDRComments], [CDRCommentsRtf], [RIAWA], [RIAWADate], [EducationAndTraining], [EducationAndTrainingDate], [Internship], [InternshipDate], [Apprenticeship], [ApprenticeshipDate], [Entrepreneurship], [EntrepreneurshipDate], [EmploymentPrep], [EmploymentPrepDate], [OTPrep], [OTPrepDate], [ExitInterview], [ExitInterviewDate], [CreatedOn], [CreatedBy], [ModifiedBy], [BCPermInEligibility], [CCPermInEligibility], [M2EligibilityDate], [CDREligibilityDate], [ExitSeparationCode], [ExitSeparationSubCode])
    Don't forget to mark helpful posts, and answers. It helps others to find relevant posts to the same question.

  • Merge rows into a single row

    select OPRCLASS,BUSINESS_UNIT from ps_sec_bu_cls where oprclass like 'OHRL_ADA01%';
    OPRCLASS BUSINESS_UNIT
    OHRL_ADA01 ADA01
    OHRL_ADA01 PRT01
    OHRL_ADA01 STATE
    How can i merge all the BUSINESS_UNIT rows into one row with a delimiter?
    OPRCLASS BUSINESS_UNIT
    OHRL_ADA01 ADA01, PRT01, STATE

    One possible solution: STRAGG

  • Noob needs help with hosting multiple sites

    Hello I am new to this multi hosting. I have looked on the forum for answers but haven't found any. I am trying to figure out how to host multiple sites. I have my dns working for my default site "example1.com", but need to know if I need to add another dns record for my second site. "example2.com". Also when I point to the new fold that has the second site in it and I assign it port 82 for testing purposes I get an error message saying 403 access forbidden. I need to find out how get permission to view the site for the public. Its in a separate folder on an external hard drive right now for testing purposes. Can any body help me or point me in the right direction? Thanks so much!!!
    -Kcam1999

    {quote}
    While what you are telling him is technically functional, it is not correct
    I beg to differ, Paul. You are the one that is not correct.
    CNAMES have been deprecated as of some years ago
    What? huh? really?
    Please show me any official document that states this (and not someone who just started a rumor because he didn't understand them). Indeed, the DNS RFC makes no such claim.
    {quote}
    I stand very much corrected. CNAMEs are not officially deprecated. Interestingly, your post cites precisely what happens when CNAMES used carelessly. How many transactions are needed to resolve Apple's CNAME chain below? RFC1912 (http://www.faqs.org/rfcs/rfc1912.html) has some recommendations that suggests Apple's own network folks have, like me and perhaps even others here, some learning to do. Is that a 'best practice?'
    {quote}> Then make sure you tell Apple since this site depends on the use of CNAMEs:
    dig discussions.apple.com
    discussions.apple.com. 492 IN CNAME discussions.apple.com.edgesuite.net.
    discussions.apple.com.edgesuite.net. 4427 IN CNAME a1399.b.akamai.net.
    a1399.b.akamai.net. 2 IN A 128.241.220.82
    a1399.b.akamai.net. 2 IN A 128.241.220.72
    In fact, it uses TWO CNAMES in a chain. Oh my.{quote}
    From RFC1912 (which I'm sure many have now read here), section 2.4 is as follows:
    {quote}... having chained records such as CNAMEs pointing to CNAMEs may
    make administration issues easier, but is known to tickle bugs in
    some resolvers that fail to check loops correctly. As a result some
    hosts may not be able to resolve such names.{quote}
    {quote}> It is not valid to say "don't use these because they could cause problems'. A records can be just as problematic, as can PTRs. Let's not even talk about MX.{quote}
    How, exactly, does is an A record problematic? No chains, no additional lookups, no wasted cycles...
    We differ here -- and if we are dealing with a newbie, we don't need to enter into unnecessary complexity UNTIL it is a requirement for their solutions.
    {quote}> There are many valid reasons to use CNAMEs in DNS, not least of which is the ease of moving a service if it uses CNAMEs. For example, if you have 10 A records all pointing at the same server and you want to migrate to a different machine you have to locate and update all 10 records. If they used a CNAME to the physical server you could move them all at once using a single change. This is especially important in cross-domain links where you may not control all the origin zone files.
    {quote}
    You're somewhat reaching here, and it is well beyond the scope of the OP's post or needs (well, until they tell us more about their needs, I suppose). There is nothing difficult about 'finding' and updating the necessary records. The final example you gave is a good one and I'll say THAT is an appropriate use of a CNAME, 'though there are other workarounds for it.
    Thanks for keeping me honest.

  • Need help with loading MySQL results into a query

    Hello, I need some help figuring out why my tree component
    isn't being populated with my MySQL results.
    I have a table of categories:
    ParentID - CategoryID - Name
    Every top-level category has a ParentID of 0 (zero). I'm
    using php and a recursive function to build an array of nested
    results, then passing those results back to Flex, making those
    results a new ArrayCollection, then assigning that to the
    dataProvider of the tree.
    Result: my tree component is blank
    Suspicion: it has to be a way with how my array is being
    formed in PHP. If I play around with how it is formed I can get
    some odd results in the tree, so I know it's not a problem with the
    data being passed back to Flex.
    I am attaching the PHP code used to form the array, and the
    output of the array being created

    Why not just build xml and send it back? Xml is hierarchical
    by nature.
    However, if you want to stick with the nested ACs then are
    you using a labelFunction() with your tree? The node values are in
    different properties, so you can't just set labelField.
    Tracy

  • I need help with making multiple measurements

    Hello,
       I have photoshop cs6 extended addition and was told photoshop would work for the research application I need but so far I am finding it very difficult to do what I want.  Basically, I need to be able to meausre multiple lines (the red ones in the screen shot) of an image precisely, and make sure that the lines I measure are documented so that they are actually visiable (so not just with the ruler tool) on the screen and labeled.  Does anyone have any idea how to approach this problem?  See image for example.  I need the lengths (converted with the 2 micrometer scale at the bottom of the image).  When I use the info, it gives me the lengths, but I can't save them, or look them up at a different time.  Also, when using the line tool, then doing the "record measurement" it does not give me the length of the line but insted acts like it is a thin rectangle and gives me a height (which does not seem to be the same as if I used the measurement tool and put it next to the line, which is an idea I have, but not as accurate) and a width.  Ideas?

    Curt,
       I tried what you said but am still confused.  First, while I will be viewing a few pictures, I am just concerned with getting the process to work with ONE picture measuring all the lines I need for it before worrying about other pictures.  I don't understand what you mean when you say making a scale for each picture of any size.  Its not about plotting a scale on the picture (I already have that in the form of the 2 micron line) its a matter of drawing new lines on top of the picture and calculating the lengths of those lines (like the red lines I put in the original screen shot).  Do you understand?
    After I make the box around the 2 micron scale in the image, then press copy then press paste, nothing seems to happen.  So when I Click NEW and it opens a new window (for a completely new workspace) nothing different happens.  You meant to click "New" after first going to the top and selecting "file" right?
    Since I am having trouble with that step, im not sure I can do the rest.
    For step 2, What do you mean by "In background content click the dropdown box and select Transparent."   ALl I see is a layer called background on the right.  I can right click on it and set the opacity to 0, but I don't see the term 'transparent' to actually select.
    Like for step three, how could I delete the selection I made by dragging to the trash?  Once I press on it, it resets.....
    Ok not sure whatelse I can ask since I couldn't really do the first step anyways....

  • Need help on inserting multiple records into database

    Hello every body,
    In my web page there is multiple select box.In that contains
    service-servicecategory-priority-filecontent -data in each item.
    suppose if select ten items and press submit button then that ten item schould be insert into database at a time. I don't know how to do?
    if any body know or any sample code ..plz help me.
    thanks in advance.

    suppose if select ten items and press submit button
    then that ten item schould be insert into database at
    a time. I don't know how to do?
    if any body know or any sample code ..plz help me.I'll give you the answer if you give me dukes.

  • Need help with Expressions to get the sum of rows between dates

     Date              Total
    8/06/2010     $2000
    8/10/2010    $5000
    8/28/2010      $2500
    9/10/2010    $5000
    9/16/2010   $2000
    9/25/2010   $7000
    9/28/2010     $2500
    I need sum of rows based on month. I have tried  following syntax. It did not work, which is returning $0.  Appreciate any help i get.
    =sum(iif(Date.value>="8/01/2010" AND Date.value<="8/30/2010",Total.value,0))

    Hi RG K,
    According to your description, you want to calculate sum of total based on month use expression, but the expression does not work. If that is the case, please refer to the following steps:
    In design surface, right-click Insert and click Text Box.
    Right-click inside of the text box, then click expression.
    In Expression text box, type the expression like below:
    =sum(iif(Fields!Date.Value>="8/01/2010" AND Fields!Date.Value<="8/30/2010",Fields!total.Value,CDec(0)))
    In this expression, the data type of total is Decimal, so we need to convert 0 to Decimal use CDec() function. If data type of total is Double, we need to use CDbl() function.
    The following screenshot is for your reference:
    If you have any more questions, please feel free to ask.
    Thanks,
    Wendy Fu
    Wendy Fu
    TechNet Community Support

  • Need help with loading child .swf into parent .swf

    Hello,
    I am having trouble with an external .swf that isbeing loaded
    into the master.swf. All of the files loads perfectly. However the
    .swf that has the contact form movieclip in it will not work. The
    combobox does that display any of the items listed and the form is
    not being sent to the server. Can anyone give me a hand with
    this?

    can you post your code

  • I need help with turning notifications back on in RH 7...

    Good morning!
    I accidentally clicked the "Don't notify me again" checkbox on a notification window - how can I get my notifications back? As of now, any files that are outside of my project folders or whatnot aren't readily visible to me because I turned this off. These notifications I'm referring to are the ones that pop up when you first open the project and look like this:
    Does anyone know how to turn this notification back on? Thanks!!

    Hi there
    See if the link below helps you sort things.
    Click here to view
    I think number 13 is what you are looking for.
    Cheers... Rick
    Helpful and Handy Links
    RoboHelp Wish Form/Bug Reporting Form
    Begin learning RoboHelp HTML 7 or 8 within the day - $24.95!
    Adobe Certified RoboHelp HTML Training
    SorcerStone Blog
    RoboHelp eBooks

  • Need help with importing flash/swf into fireworks???? Is it possible???

    Hi, Is it possible to import a flash/swf file in to
    fireworks... If so... how..????
    Thank You for Your Help...

    can you post your code

Maybe you are looking for

  • Internal Hard Drive Won't Boot or Mount

    I don't know if this is the right forum for this but... My 24" iMac running 10.5.2 won't start up. Meaning I can't get past the grey screen. I fsck the disk in single user mode and got back "invalid nobe structure (4,19621)" and repairs failed, then

  • JDBC, Oracle: access denied

    I can load Oracle driver Class.forName("oracle.jdbc.driver.OracleDriver"); But in this string: String url = "jdbc:oracle:thin:@195.52.61.6:1521:ORCL"; java.sql.Connection con = java.sql.DriverManager.getConnection(url, "SCOTT", "TIGER"); happens exce

  • Movie start points in a session

    In addition to my previous post, i have a problem with Movie start points and tempo changes as well. Please correct me if i am wrong but in Logic 7 it was possible to set a movie smpte point (say 10.20.17.22) as Bar 1 of the arrangement thus meaning

  • Download & install

    Morning, need to download and install Adobe Photoshop cs3... how can i get it??

  • Config SCVMM in TFS

    Hi  I want to create SCVMM Environment in MTM, but it's check box is unchecked, and say : to enable this option, Configure System Center Virtual Machine Manager in Team Foundation Server, and a host group for you'er team project. I have one team proj