Eliminate repeating column values

Hi,
I have my source table below values:
CLIENT_ID BEGIN_DT END_DT R RES_TYPE_DESC
109800001 20-MAR-97 23-AUG-98 2 FOSTER/COMPANION CARE RESIDENTIAL COMPON
109800001 24-AUG-98 03-SEP-98 1 SHIFT STAFF RESIDENTIAL COMPONENT 3 BED
109800001 04-SEP-98 18-MAR-00 2 FOSTER/COMPANION CARE RESIDENTIAL COMPON
121874001 20-MAR-98 15-DEC-03 2 FOSTER/COMPANION CARE RESIDENTIAL COMPON
121874001 14-MAY-97 15-DEC-03 2 FOSTER/COMPANION CARE RESIDENTIAL COMPON
121874001 16-DEC-03 11-MAY-05 4 SUPERVISED LIVING
504407361 07-SEP-97 05-SEP-07 3 OWN/FAMILY HOME
504564902 06-NOV-97 03-NOV-06 3 OWN/FAMILY HOME
506169803 20-AUG-97 31-MAY-99 3 OWN/FAMILY HOME
506169803 01-JUN-99 29-FEB-00 1 SHIFT STAFF RESIDENTIAL COMPONENT 3 BED
506169803 01-MAR-00 18-AUG-02 4 SUPERVISED LIVING
CLIENT_ID BEGIN_DT END_DT R RES_TYPE_DESC
506169803 19-AUG-02 24-JUL-03 5 RESIDENTIAL SUPPORT SERVICE
506169803 25-JUL-03 23-JUN-04 2 FOSTER/COMPANION CARE RESIDENTIAL COMPON
506169803 24-JUN-04 17-AUG-05 5 RESIDENTIAL SUPPORT SERVICE
14 rows selected.
at row no 4 and 5 for client_id = '121874001'
It has repeating END_DT = '15-DEC-03'
I want to have only one record for client_id = '121874001' where BEGIN_DT IS MINIMUM begin_Dt value (i.e. begin_Dt = '14-MAY-97' and END_DT = '15-DEC-03')
so I can have 2 rows instead of 3 rows for client_id = '121874001'
This is part of my table records my table contains multiple clients.
can some one help me writing SQL ?
Thanks in advance
Jay

To display non-repeating information while showing the minimun begin_dt, you need to apply the aggregate funtion MIN to the begin_dt column and the GROUP BY clause to the rest of the columns, as follows:
SELECT client_id, MIN(begin_dt) BEGIN_DT, end_dt, r, res_type_desc
FROM your_source_table
GROUP BY client_id, end_dt, r, res_type_desc;
(use your real column names; your pasted result set seems to append some column names)
Good luck,
Luis

Similar Messages

  • Repeat Column Value derived from formulae

    I need to repeat a value derived for a particular column &row combination to all rows in the table. however when I put the 'case' function it does not repeat the values as I expect. The value is only shown in the 1at row
    The formulae used is as follows
    CASE WHEN D_MILLS.MILL_NO =1 THEN (F_MILL_PRODUCTION.FN_YTD_CPO_PRODUCED/F_MILL_PRODUCTION.FN_YTD_CROP_PROCESSED ) ELSE (FILTER(F_MILL_PRODUCTION.FN_YTD_CPO_PRODUCED/F_MILL_PRODUCTION.FN_YTD_CROP_PROCESSED USING (D_MILLS.MILL_NO = 1.00)) ) END
    Note : Mill No is the Dimension Field that I user for the report. and I require the value of derived for mill No =1 to be repeated to all other mills (Mill No =2,3 etc)
    Edited by: Shaz01 on Aug 7, 2010 1:45 AM

    Hi,
    Use the formula like this,
    Max(CASE WHEN D_MILLS.MILL_NO =1 THEN (F_MILL_PRODUCTION.FN_YTD_CPO_PRODUCED/F_MILL_PRODUCTION.FN_YTD_CROP_PROCESSED ) ELSE (FILTER(F_MILL_PRODUCTION.FN_YTD_CPO_PRODUCED/F_MILL_PRODUCTION.FN_YTD_CROP_PROCESSED USING (D_MILLS.MILL_NO = 1.00)) ) END)
    Also for all the values you need to show the value of Mill no 1, so no need for case statement.
    MAX(FILTER(F_MILL_PRODUCTION.FN_YTD_CPO_PRODUCED/F_MILL_PRODUCTION.FN_YTD_CROP_PROCESSED USING (D_MILLS.MILL_NO = 1.00)))
    Thanks,
    Vino

  • Query- not to repeat  column value

    Hello,
    tried find the solution from the forum... but no luck ....if it repeation please excuse me.
    Data on the Table.
    ID       U_ID     NAME     
    100     1          AAA
    100     3          BBB
    200     1          CC
    200     2          DDD
    200     3          EEEEMy output Should be
    ID       U_ID     NAME     
    100     1          AAA
              3          BBB
    200     1          CC
              2          DDD
              3          EEEENo repetation of ID
    Kindly suggest me.
    Thanks,
    Amuly

    with t as
    (select '100' ID,'1' U_ID,'AAA' NAME from dual union all
    select '100','3','BBB' from dual union all
    select '200','1','CC' from dual union all
    select '200','2','DDD' from dual union all
    select '200','3','EEEE' from dual)
    select decode(row_number() over(partition by ID order by name),1,id) ID,u_id,name
    from t;
    ID U NAME
    100 1 AAA
    3 BBB
    200 1 CC
    2 DDD
    3 EEEE
    Thanks,
    Ramadurga
    Edited by: 968136 on Nov 2, 2012 12:20 PM

  • How to not repeat the column values if repeated on next line and so on..?

    Hi all,
    The XmlP template that is designed gives me the output as follows :
    COL1 COL2 COL3 COL4 COL5 COL6 COL7
    abc 1 1000.00 10.00 95.00 695.00 cad
    abc 2 1000.00 100.00 95.00 695.00 cad
    abc 3 1000.00 100.00 95.00 695.00 cad
    But my requirement is as follows :
    COL1 COL2 COL3 COL4 COL5 COL6 COL7
    abc 1 1000.00 10.00 95.00 795.00 cad
    - 2 - 100.00 - - -
    - 3 - 100.00 - - -
    Note : "-" indicates blank column values (gaps are being filled)
    How do I not repeat the column values if repeated?
    Please let me know if you have answer for it?
    Thanks in Advance
    Munna

    Iam trying to design the xml publisher template using xmlp template builder.
    My requirement is :
    For a receipt number, I have receipt amount, applied amount, unapplied amount and on account amount. And for each receipt, there can be multiple applied amount ( as the receipt can be applied multiple times), but the unapplied amount, on account amount and receipt amount is single.
    By using the logic as said above from http://blogs.oracle.com/xmlpublisher/2007/04/13
    Iam getting the output something like this:
    Receipt Number| Receipt Amount | App Amount |UnappAmount|OnaccountAmount|
    111-b|249.28|249.28|0.00|0.00|
    1110|1,000.00|10.00|95.00|795.00|
    1110| -|10.00|-|-|
    1112|1500.00|1,271.02|-|-|
    1112|-|228.98|-|-|
    My requirement is to go get something like this:
    Receipt Number| Receipt Amount | App Amount |UnappAmount|OnaccountAmount|
    111-b|249.28|249.28|0.00|0.00|
    1110|1,000.00|10.00|95.00|795.00|
    1110| -|10.00|-|-|
    1112|1500.00|1,271.02|0.00|0.00| ---> here lies the difference
    1112|-|228.98|-|-|
    How do i check the duplicate of the column values only for a receipt number??
    Because as for receipt no. 111-b the unapplied amount and on account amount is 0.00, the the unapplied amount and on account amount for receipt number 1112 is getting hided( because its a duplicate) . In reality, it should be 0.00 and any other line for that receipt number (1112) should be hided. except for the applied amount.
    Note We can see that last 2 columns in the last record( for receipt number 1112) is getting hided that is as expected but for 4th record the unapplied amount and on account amount should be 0.00 respecively.
    '-' indicates hided value
    Please help.
    Thanks in Advance

  • How to repeat rows based on column value

    Hi all,
    I have a query that gives me a result with a column value for example 4.
    I now want to repeat this row 4 times with a new column that calculated from 1 - 4.
    Or when column value is 3 I want to repeat row 3 times with new column name 1-3
    Can anyone help me with this please? :)

    Hi Yvanlathem,
    To achieve your requirement, you can reference the recursive approach as below.
    DECLARE @T TABLE(Col1 CHAR(1),Col2 INT)
    INSERT INTO @T VALUES('A',1),('B',2),('C',3)
    ;WITH Cte([Char],[Repeat]) AS
    SELECT Col1,Col2 FROM @T
    UNION ALL
    SELECT [Char],[Repeat]-1 FROM Cte
    WHERE [Repeat]>1
    SELECT * FROM Cte ORDER BY [Char],[Repeat]
    OPTION(MAXRECURSION 0)
    /* Output
    Char Repeat
    A 1
    B 1
    B 2
    C 1
    C 2
    C 3
    If you have any question, feel free to let me know.
    Eric Zhang
    TechNet Community Support

  • Referencing Aggregated Column Value in Where Clause

    Hello -
    I'm trying to determine how I can accomplish the following in the most straightforward, efficient way.
    Among other things, I'm selecting the following value from my table:
    max(received_date) as last_received_dateI also need to evaluate the "last_received_date" value as a condition in my where clause. However, I can't reference my aliased "last_received_date" column value, and when I try to evaluate max(received_date) in the where clause, I get the "group function is not allowed here" error.
    Does anyone know of a good workaround?
    Thanks,
    Christine

    Hi,
    Column aliases can be used in the ORDER BY clause: aside from that, they cannot be used in the same query where they are defined. The workarounds are
    (a) define the alias in a sub-query, and use it in a super-query, like Someoneelse did, or
    (b) repeat the aliased expression, as in the HAVING-clause, below.
    Aggregate functions are computed after the WHERE-clause. (That explains why you can do things like
    SELECT  MAX (received_date) last_received_date_2008
    FROM    table_x
    WHERE   TO_CHAR (received_date, 'YYYY')  = '2008';).
    The HAVING-clause is like the WHERE-clause, but it is applied after the aggregate functions are computed, e.g.
    SELECT    deptno
    ,         MAX (recieved_date)  AS last_received_date
    FROM      table_x
    GROUP BY  deptno
    HAVING    MAX (received_date)    > SYSDATE - 7   -- Only show deptartments with activity in the last week
    ;

  • FSG report not printing column values on same line but sequentially

    FSG report problem:
    We have defined 2 FSG reports 'Balance Sheet - Total' and 'Balance Sheet - Detail'. Both reports have 3 column values, namely the value in Euro (our Functional Currency), the value in MUR - Mauritian rupees (our reporting currency) and the rate of exchange.
    The report 'Balance Sheet - Total' displays these values for assets e.g.:-
    EURO MUR Rate of exchange
    Non-current assets
    1. Intangible assets ? ? ?
    2. Other investments ? ? ?
    (note: ? represents a certain value)
    The report 'Balance Sheet - Detail' displays values as follows :-
    Account EURO MUR Rate of exchange
    1. Property & Equipment
    A10101 Building Cost ? 0.00 0.0000
    A20105 Motor Veh Accum Dep ? 0.00 0.0000
    TOTAL ? 0.00 0.0000
    A10101 Building Cost 0.00 ? n/m
    A20105 Motor Veh Accum Dep 0.00 ? n/m
    (note: ? represents a certain value)
    What we don't understand s why the 'Balance Sheet - Detail' report repeats the display of column values in MUR FOLLOWING the display in EURO, instead of displaying column values for EURO and MUR on the same line, just like in the case for 'Balance Sheet - Total'.
    Is there anything in the definition of column set, row set or report set should I change?
    Can anybody help. Thanks.
    null

    The problem is related to defining the column set properly. It is OK with the first report and needs modification for the second. Formatting is also important so that they appear in the same line(row). The columns need to be linked to the fileds and assignment to set of books is also important as mentioned by Rajsekhar

  • Tabular form query using column values delimiter

    I wanted to know, if i can query a tabular block by entering the column values (primary key) as semicolon delimited and update required fields. Please let me know.
    Requirement:-
    User will enter 5 values as "AB1; AB2; AB3; AB4; AB5"
    After entering I need to write a plsql code to query the tabular form as follows
    PrimaryCol SecCol
    AB1 IN
    AB2 IN
    AB3 OUT
    AB4 IN
    AB5 ON
    Then I will update the columns accordingly.
    Please help me.

    You could put something like this in the WHERE-clause (assuming that :BLOCK.QUERYDATA contains your value AB1;AB2;AB3;AB4; )
    INSTR (';' || PK_COLUMN || ';', ';' || :BLOCK.QUERYDATA || ';')>0Maybe you have to additionally eliminate space in :BLOCK.QUERYDATA

  • Column values as Page Header

    Hi All,
    I want to display some column values like Company_Name, Company_Address etc in the Page Header of the report. I am fetching these values from table in the query of my report. Can somebody tell me how I can do that?
    I tried placing a repeating frame in upper area of margin in 'Main Section' of report. Source of the frame was Query group. It printed multiple headers on one page.
    Waiting for your replies. Thanks in advance.
    Regards
    Mona

    I think your query is return more then one record or u create query as child .
    Create a query company name, address etc. as parent and other information as a child query, and link them with link tool.
    Example
    Q1. Select customer_no,name,address from customer (Parent)
    Q2. Select customer_no, invoice_no, amount from invoices (Child)
    If u created query like this
    Select c.customer_no,c.name,c.address, i.invoice_no, i.amount
    from customer c, invoices i
    where c.customer_no=i.customer_no;
    its return name and address for every record of invoices table.
    Qadeer

  • Getting count of occurances of a string in a column value

    Hi,
    Is there a way to get the number of occurences of a string in a single column value?
    Example:
    CREATE TABLE STRING_CNT(X VARCHAR2(100));
    INSERT INTO STRING_CNT(X) VALUES('OracleXXOracleXXOracleXXOracle');
    Commit;
    Now the string 'Oracle' is repeated 4 times in the inserted value. I would like to get this count using SQL.Can some one tell me how to get this?
    I was asked this interesting question in an interview today.

    hi<br>
    u can get the occurrence of a string in text as
    follow<br>
    >
    SELECT (LENGTH(x)-LENGTH(REPLACE(x,'Oracle', ' ' )))<br>
    / LENGTH('Oracle') as<br>
    Occurrence FROM STRING_CNT;<br><br>
    <br>
    Are you sure...?<br>
    <br>
    <br>
    SQL> with STRING_CNT as
      2  (select '1.Oracle2.Oracle3.' x
      3  from dual)
      4  SELECT (LENGTH(x)-LENGTH(REPLACE(x,'Oracle', ' ' ))) / LENGTH('Oracle') as Occurrence
      5  FROM STRING_CNT;
    OCCURRENCE
    1.66666667
    <br>
    Sidenote: Please give a try before posting..<br>
    And you are posting a wrong solution after a TESTED right solution posted hours before..                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Permanently set Repeat cell values on table view obiee11g

    Hi,
    By default Analysis presentation Column comes with "Column Value Suppression" but we need to switch "Column Value Suppression" to "Repeat cell values" from source xml reference file
    Note:don't want to do it via analysis table/column properties(its manual work) ..just looking to change permanently by changing xml
    Thanks
    Deva

    Hi,
    What is that datatypeformats.xml ? couldn't find out. once again will explain my requirement
    Creating new analysis(Table/Pivot table view) and applying format as Repeat Cell by changing Table/Pivot Properties to set Enable alternating row "green bar" styling Repeat cell values on table/pivot view (instead of doing manual way)
    Refer the below image --> i just want to avoid manual enabling below Repeat cell option for entire table/pivot view option
    http://i.imgur.com/122wp.jpg?1
    Thanks
    Deva
    Edited by: Devarasu on Nov 26, 2012 5:06 PM

  • Repeated column in mapping error - Hibernate mapping

    Hi, I am relatively new to using Hibernate. I have two tables which I have tried to map unsuccesfully.
    Table 1:
    Primary Key(Instrument) -> Generated using function.
    Table 2:
    Primary Key(Instrument) -> Referenced from primary key of table 1
    Table 3:
    Primary Key(Instrument) -> Referenced from primary key of table 2
    Additional Column(Parent_Instrument) -> Referenced from the primary key of table 2
    So, two columns in Table 3 have to be mapped to the primary key of table 2.
    I have tried mapping them but am getting the following error:
    Caused by: org.hibernate.MappingException: Repeated column in mapping for entity: com.db.csb.model.securitycreation.entities.tradegate.WiBonds column: INSTRUMENT (should be mapped with insert="false" update="false")
         at org.hibernate.mapping.PersistentClass.checkColumnDuplication(PersistentClass.java:652)
         at org.hibernate.mapping.PersistentClass.checkPropertyColumnDuplication(PersistentClass.java:674)
         at org.hibernate.mapping.PersistentClass.checkColumnDuplication(PersistentClass.java:696)
         at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:450)
         at org.hibernate.mapping.RootClass.validate(RootClass.java:192)
         at org.hibernate.cfg.Configuration.validate(Configuration.java:1102)
         at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1287)
         at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:915)
         at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:807)
         at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:740)
         at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:131)
         at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1062)
         at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1029)
         ... 32 moreThe following is my code:
    TABLE 2
    @Entity
    @Table(name="BOND_SPEC")
    @Id
         @GenericGenerator
         @GeneratedValue
         @Column(name="INSTRUMENT", nullable=false,insertable=false,updatable=false)
         public long getInstrument() {
              return instrument;
         public void setInstrument(long instrument) {
              this.instrument = instrument;
    @OneToMany
         @JoinColumn(name = "INSTRUMENT", nullable=false, insertable=false)
         public Set<WiBonds> getWiBonds(){
              return Wi_Bonds;
         public void setWiBonds(Set<WiBonds> Wi_Bonds){
              this.Wi_Bonds = Wi_Bonds;
    TABLE 3
    @Entity
    @Table(name="WI_BONDS")
         @Id
         @GenericGenerator(name = "fk_bondspec", strategy = "foreign", parameters = { @Parameter(name = "property", value = "BondSpec") })
         @GeneratedValue(generator = "fk_bondspec")
         @Column(name="INSTRUMENT", nullable=false,insertable=false,updatable=false)     
         public long getInstrument() {
              return instrument;
         public void setInstrument(long instrument) {
              this.instrument = instrument;
         @ManyToOne(targetEntity = BondSpec.class)
         @JoinColumn(name = "INSTRUMENT", nullable = false, insertable=false, updatable=false)
         public BondSpec getBondSpec() {
         public void setbondSpec(BondSpec bondspec) {
         @OneToOne(targetEntity = BondSpec.class)
         @JoinColumn(name = "PARENT_INSTRUMENT", nullable = false, insertable = false, updatable = false, unique=true)
         public long getParent_instrument() {
         public void setParent_instrument(long parent_instrument) {
         }What am I doing wrong?

    theraptor wrote:
    I probably didn't explain it correctly. I am trying to populate these tables with data about financial instruments.
    Table 2 and 3 share a primary key (INSTRUMENT). The primary key is generated in table 2, and the same value has to be later inserted into table 3. Sorry, I'm not following this at all. I don't think two tables should "share" a primary key. Both should have their own. Perhaps Table 3 would have a foreign key relationship with Table 2. OR the two tables should be one. But this notion of sharing doesn't sound right to me, and apparently Hibernate agrees. I think you have a bad design.
    Table 2 has a one to many relation with table 3. Then they can't share a primary key. It's 1:m, which you can easily model with Hibernate.
    (By many I mean it could be 0 as well, since hibernate does not provide a (one to 'maybe' one 'maybe zero) relation.Fine. Then it's a 1:m relationship. You've been thinking about it incorrect.
    Table 3 has an additional column PARENT_INSTRUMENT which is a foreign key to the the primary key of table 2.No. Wrong.
    Yes Instrument is financial in nature. However, I am not trying to model what you have spoken about above.Yes, I get it. Listen to Hibernate - your original idea is quite incorrect. Table 2 is 1:m with Table 3. Model it that way, and forget about this incorrect notion of "sharing a primary key". Give Table 3 its own auto generated key.
    %

  • How to read repeated tag values using sql query

    Database version
    Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
    PL/SQL Release 11.2.0.2.0 - Production
    CORE 11.2.0.2.0 Production
    TNS for Linux: Version 11.2.0.2.0 - Production
    NLSRTL Version 11.2.0.2.0 - Production
    Question
    How to get repeated tag values?
    <TXLife>
    <TXLifeRequest>
    <TransRefGUID>10bc80e7d60e59b0:a134d0:10d7c4674ad:-7ffd</TransRefGUID>
    <TransType tc="1203">OLI_TRANS_TRNHLD</TransType>
    <TransExeDate>2011-02-27</TransExeDate>
    <TransExeTime>15:06:35</TransExeTime>
    <InquiryLevel tc="3">OLI_INQUIRY_OBJRELOBJ</InquiryLevel>
    <InquiryView>
    <InquiryViewCode>PLANUPDATE_CHBM_1203A</InquiryViewCode>
    </InquiryView>
    <OLifE>
    <SourceInfo>
    <SourceInfoName>CHBM Admin Tool</SourceInfoName>
    </SourceInfo>
    <Activity id="Activity1" HoldingID="Holding1">
    <UserCode>User123</UserCode>
    <LastUpdate>2011-02-27</LastUpdate>
    <ActivityCode>CHBM10001</ActivityCode>
    <OLifEExtension VendorCode="0098" ExtensionCode="Activity">
    <ActivityExtension>
    <SubActivityCode>CHBM20002</SubActivityCode>
    <LastUpdateTime>15:06:35</LastUpdateTime>
    </ActivityExtension>
    </OLifEExtension>
    </Activity>
    <Holding id="Holding1">
    <HoldingTypeCode tc="6">Group Master Contract</HoldingTypeCode>
    <Purpose tc="36">Business Protection and Preservation</Purpose>
    <Policy>
    <CarrierAdminSystem>CHBM</CarrierAdminSystem>
    <PolNumber>CHB0001234</PolNumber>
    <OLifEExtension VendorCode="0098" ExtensionCode="Policy">
    <PolicyExtension>
    <BillingDetail>
    <PaymentMode tc="3">Quarterly</PaymentMode>
    <BillingOrder tc="1009800002">Employee ID</BillingOrder>
    </BillingDetail>
    <SalaryAllotment>12354333</SalaryAllotment>
    </PolicyExtension>
    </OLifEExtension>
    </Policy>
    <Attachment id="Attach1">
    <DateCreated>2011-02-27</DateCreated>
    <UserCode>System</UserCode>
    <AttachmentBasicType tc="1">Text</AttachmentBasicType>
    <Description>Event 4</Description>
    <AttachmentData>Event Log</AttachmentData>
    <AttachmentType tc="1009800001">Transaction Log</AttachmentType>
    <AttachmentLocation tc="1">Inline</AttachmentLocation>
    <OLifEExtension VendorCode="0098" ExtensionCode="Attachment">
    <AttachmentExtension>
    <Sequence>2</Sequence>
    <CreationTime>16:05:45</CreationTime>
    </AttachmentExtension>
    </OLifEExtension>
    </Attachment>
    <Attachment id="Attach2">
    <DateCreated>2011-02-27</DateCreated>
    <UserCode>System</UserCode>
    <AttachmentBasicType tc="1">Text</AttachmentBasicType>
    <Description>Event 3</Description>
    <AttachmentData>Event Log</AttachmentData>
    <AttachmentType tc="1009800001">Transaction Log</AttachmentType>
    <AttachmentLocation tc="1">Inline</AttachmentLocation>
    <OLifEExtension VendorCode="0098" ExtensionCode="Attachment">
    <AttachmentExtension>
    <Sequence>1</Sequence>
    <CreationTime>16:01:54</CreationTime>
    </AttachmentExtension>
    </OLifEExtension>
    </Attachment>
    <Attachment id="Attach3">
    <DateCreated>2011-02-27</DateCreated>
    <UserCode>P62350</UserCode>
    <AttachmentBasicType tc="1">Text</AttachmentBasicType>
    <Description>Note 2</Description>
    <AttachmentData>Enter notes on changes or edits to plan</AttachmentData>
    <AttachmentType tc="14">Note</AttachmentType>
    <AttachmentLocation tc="1">Inline</AttachmentLocation>
    <OLifEExtension VendorCode="0098" ExtensionCode="Attachment">
    <AttachmentExtension>
    <Sequence>2</Sequence>
    <CreationTime>16:02:23</CreationTime>
    </AttachmentExtension>
    </OLifEExtension>
    </Attachment>
    </Holding>
    </OLifE>
    </TXLifeRequest>
    </TXLife>
    Expected output shoulb be like this
    Description AttachmentType AttachmentData
    Event 4 Transaction Log Event Log
    Event 3 Transaction Log Event Log
    Note 2 Note Enter notes on changes or edits to plan
    Please help me any one on this
    Edited by: LRAJESH on Apr 20, 2011 8:27 AM

    SELECT
    t2. Description des,
    t2.AttachmentType attty,
    t2.DateCreated DateCreated,
    t2.UserCode UserCode,
    t1.Planid Planid,
    t2.createdtime,
    t1.Ausercode Ausercode
    FROM (
    SELECT xData doc
    FROM dual
    ) temp_table,
    XMLTable ( '/TXLife/TXLifeRequest/OLifE' passing doc
    COLUMNS
    Planid varchar2(20) path 'Holding/Policy/PolNumber',
    AttachmentType xmltype path 'Holding//Attachment' ,
    Ausercode varchar2(20) path 'Activity/UserCode'
    ) t1,
    XMLTable
    '/Attachment'
    passing t1.AttachmentType
    columns
    Description varchar2(1000) path 'Description',
    AttachmentType varchar2(1000) path 'AttachmentType/@tc',
    DateCreated varchar2(20) path 'DateCreated',
    createdtime varchar2(20) path 'OLifEExtension/AttachmentExtension/CreationTime',
    UserCode varchar2(200) path 'UserCode'
    ) t2

  • Better approach for checking column values between two different rows

    My requirement is to find best Approach to find difference between column values of two different rows.Below I've mentioned two different
    approaches I'm thinking of,but I'd like to know is there any other better approach.
    version details
    SQL> SELECT *
      2  FROM V$VERSION;
    BANNER
    Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production
    PL/SQL Release 11.1.0.7.0 - Production
    CORE    11.1.0.7.0      Production
    TNS for Solaris: Version 11.1.0.7.0 - Production
    NLSRTL Version 11.1.0.7.0 - ProductionTable creation script
    CREATE TABLE R_DUMMY
       (CA_ID VARCHAR2(16) NOT NULL ENABLE,
         CA_VER_NUM NUMBER(4,2) NOT NULL ENABLE,
         BRWR_SHORT_NAME VARCHAR2(25 CHAR),
         sic_code     number,
         FAC_ID VARCHAR2(10) NOT NULL ENABLE
    / insert script
    insert into r_dummy (CA_ID, CA_VER_NUM, BRWR_SHORT_NAME, sic_code, FAC_ID)
    values ('CA2001/11/0002', 2.00, 'Nandu',1234, 'FA000008');
    insert into r_dummy (CA_ID, CA_VER_NUM, BRWR_SHORT_NAME, sic_code, FAC_ID)
    values ('CA2001/11/0002', 3.00, 'SHIJU',456, 'FA000008');Desired O/P :
    ca_id               fac_id          column_name          previous name          after_modification
    CA2001/11/0002          FA000008     BRWR_SHORT_NAME          Nandu               SHIJU
    CA2001/11/0002          FA000008     sic_code          1234               456My approach
    select      ca_id,fac_id,column_name,
         decode(column_name,'BRWR_SHORT_NAME',lg_brwr,lg_sic) previous_name ,
         decode(column_name,'BRWR_SHORT_NAME',ld_brwr,ld_sic) after_modification
    from
         select
                   case
                        when ld_brwr != lg_brwr then
                        'BRWR_SHORT_NAME'
                        when ld_brwr != lg_brwr then
                        'sic_code'
                   end
              ) column_name,ca_id,fac_id,lg_brwr,ld_brwr,ld_sic,lg_sic
         from     (
              select ca_id,fac_id,lag_brwr,ld_brwr,ld_sic,lag_sic
              from
                        Select      lead(brwr_short_name,1) over(partition by ca_id,fac_id) ld_brwr,
                             lag(brwr_short_name,1) over(partition by ca_id,fac_id) lg_brwr,
                             lead(sic_code,1) over(partition by ca_id,fac_id) ld_sic,
                             lag(sic_code,1) over(partition by ca_id,fac_id) lg_sic,
                             ca_id,fac_id
                        from r_dummy
              where (ld_brwr != lg_brwr or ld_sic != lg_sic)
    )2nd Approach :
    =============
    select      ca_id,fac_id,column_name,
         decode(column_name,'BRWR_SHORT_NAME',lg_brwr,lg_sic) previous_name ,
         decode(column_name,'BRWR_SHORT_NAME',ld_brwr,ld_sic) after_modification
    from
         select
                   case
                        when ld_brwr != lg_brwr then
                        'BRWR_SHORT_NAME'
                        when ld_brwr != lg_brwr then
                        'sic_code'
                   end
              ) column_name,ca_id,fac_id,lg_brwr,ld_brwr,ld_sic,lg_sic
         from     (
              select ca_id,fac_id,brwr_short_name,sic_code
              from
                        Select      ca_id,fac_id,brwr_short_name lg_brwr,sic_code lg_sic
                        from     r_dummy
                        where     ca_ver_num = '2.00'
                   )o,(
                        Select      ca_id,fac_id,brwr_short_name ld_brwr,sic_code ld_sic
                        from     r_dummy
                        where     ca_ver_num = '3.00'
                              )n
              where      0.ca_id = n.ca_id
                   and 0.fac_id = n.fac_id
                   and (ld_brwr != lg_brwr or ld_sic != lg_sic)
    )Hi Experts,
         I've provided sample data where I'm checking for just two columns viz brwr_short_name ,sic_code,but in real time
    I've to check for 8 more columns so please suggest me with a better approach.
    I appreciate your precious suggestions.

    Hi,
    Thanks for posting the CREATE TABLE and INSERT statements; that really helps!
    Here's one wa. Like your 2nd approach, this uses a self-join:
    WITH     got_r_num     AS
         SELECT  ca_id
         ,     ROW_NUMBER () OVER ( PARTITION BY  ca_id
                                   ,                    fac_id
                             ORDER BY        ca_ver_num
                                 )    AS r_num
         ,     brwr_short_name
         ,     TO_CHAR (sic_code)     AS sic_code
         ,     fac_id
    --     ,     ...     -- Other columns (using TO_CHAR if needed)
         FROM     r_dummy
    ,     unpivoted_data     AS
         SELECT     *
         FROM     got_r_num
         UNPIVOT     INCLUDE NULLS
              (    txt
              FOR  column_name IN ( brwr_short_name          AS 'BRWR_SHORT_NAME'
                            , sic_code               AS 'SIC_CODE'
    --                        , ...     -- Other columns
    SELECT       p.ca_id
    ,       p.fac_id
    ,       p.column_name
    ,       p.txt          AS previous_name
    ,       a.txt          AS after_modification
    FROM       unpivoted_data   p
    JOIN       unpivoted_data   a  ON  p.ca_id     = a.ca_id
                           AND p.fac_id     = a.fac_id
                         AND p.column_name     = a.column_name
                         AND p.r_num      = a.r_num - 1
                         AND p.txt || 'X' != a.txt || 'X'
    ORDER BY  a.r_num
    ;To include other columns, add them in the 2 places where I put the comment "Other columns".
    Ca_ver_num can have any values, not just 2.00 and 3.00.
    This will show cases where a value in one of the columns changed to NULL, or where NULL changed to a value.
    There ought to be a way to do this without a separate sub-query like got_r_num. According to the SQL Language manual, you can put expressions in the UPIVOT ... IN list, but when I tried
    ...     UNPIVOT     INCLUDE NULLS
              (    txt
              FOR  column_name IN ( brwr_short_name          AS 'BRWR_SHORT_NAME'
                                 , TO_CHAR (sic_code)     AS 'SIC_CODE'
              )I got the error "ORA_00917: missing comma" right after TO_CHAR. Perhaps someone else can show how to eliminate one of the sub-queries.

  • Repeat Suppressed Value after Page Throw

    Hello
    I'm new to BI Publisher and have what I think is a simple problem that I can't solve and can't see a solution to in the forum so any help would be welcome.
    I have a report which is essentially a simple, long table with three columns. The report is grouped by the first column, so that the value is suppressed after the first display. When the table breaks across a page the heading repeats fine, but I need to show the grouped value again on the first line. Is this possible?
    Thanks
    Ian

    Hi Vetsrini!
    Are you able to post the steps needed to prevent column values from repeating? I work on multiple networks so it's not possible to email you the files.
    Thank you!
    T

Maybe you are looking for

  • Sales BOM Wise Stock report

    Dear Gurus, Good Afternoon!! My user' requirement is, he wants a BOM wise stock report. He will just enter the Header Item, Plant and the storage location, and system should list all its sub-items with the stock available in that plant & the storage

  • Is it possible to write text in a REPORT in the required font and style

    Hi everyone, I have got a requirement from the client,where he asks to write some text in the report with some font size and style,Is it possible to do that in a report,if so plz reply back with piece of code. Thanks & Regards, Rajeev.N

  • Disabling Acrobat Connect and PDFMaker 8.0 permanently in Word 2003

    I wish to disable Acrobat Connect and PDFMaker 8.0 permanently in Word 2003. I've tried several things, but they Add-on keeps appearing. Can anyone help me, please?

  • Encore:  vobulator BlockPlanner error 217

    Hello, I've been building a project in Encore for days and finally went to build a DVD today, and after all the transcoding, when it went to write on the disc, it failed with the following message: internal software error: .\vobulator\BlockPlanner\Bl

  • Illust CS5 Profiles Match but Pantones Print Differently

    Ok. I have a problem with colors not matching between Illustrator CS5 documents. I am often emailed documents with pantone colors selected in them. Later, sometimes I need to create another document using those same pantone colors. The problem is, th