How to get the desired output

My Table Data
ContractID     MaterialGroup      CommodityCode     Amount
C123       Travel     200     100
C123      Travel     201     100
C123             Travel     203     100
C124            Stationery     315     500
C126            Travel             200     600
C126            Admin             413     600
My expected output
ContractID     MaterialGroup      CommodityCode     Amount
C123        Travel             200|201|203     100
C124             Stationery             315                     500
C126            Travel|Admin     200|413           600
My Present Output
CONTRACTID MATERIALGROUP    COMMODITYCODE AMOUNT
C123            Travel|Travel|Travel  200|203|201        100
C124            Stationery               315                     500
C126            Travel|Admin           200|413               600
My Query:
  SELECT ContractID,
  RTrim(
              xmlagg(
                      xmlelement(e, MaterialGroup|| '|')).extract('//text()'),'|') MaterialGroup,
  RTrim(
              xmlagg(
                      xmlelement(e, CommodityCode|| '|')).extract('//text()'),'|') CommodityCode,Amount
FROM (
WITH t1 AS (
SELECT 'C123' ContractID,     'Travel'MaterialGroup,      200     CommodityCode, 100 Amount FROM dual UNION all
SELECT 'C123',            'Travel',     201,     100 FROM dual UNION all
SELECT 'C123',            'Travel',     203,     100 FROM dual UNION all
SELECT 'C124','Stationery',     315,     500 FROM dual UNION all
SELECT 'C126','Travel',     200,     600 FROM dual UNION all
SELECT 'C126','Admin',413,     600 FROM dual)
SELECT * FROM t1)
GROUP BY ContractID,Amount;

select t.*,
        case when cdm = 1 and cm > 1
                then substr(materialgroup,1, instr(materialgroup,'|', cdm)-1)
                else materialgroup end materialgroup_edit,
         case when cdm = 1 and cm > 1 then mm else materialgroup end materialgroup_edit2
from
          select contractid,
          count(materialgroup) cm,
          count(distinct materialgroup) cdm,
          max(materialgroup) mm,
          rtrim(
                      xmlagg(
                              xmlelement(e, materialgroup|| '|')).extract('//text()'),'|') materialgroup,
          rtrim(
                      xmlagg(
                              xmlelement(e, commoditycode|| '|')).extract('//text()'),'|') commoditycode,amount
        from (
        with t1 as (
        select 'C123' contractid,    'Travel' materialgroup,     200    commoditycode, 100 amount from dual union all
        select 'C123',            'Travel',    201,    100 from dual union all
        select 'C123',            'Travel',    203,    100 from dual union all
        select 'C124','Stationery',    315,    500 from dual union all
        select 'C126','Travel',    200,    600 from dual union all
        select 'C126','Admin',413,    600 from dual  )
        select * from t1)
        group by contractid,amount
        ) t;
CONTRACTID         CM        CDM MM         MATERIALGROUP        COMMODITYCODE            AMOUNT MATERIALGROUP_EDIT   MATERIALGROUP_EDIT2
C123                3          1 Travel     Travel|Travel|Travel 200|203|201                 100 Travel               Travel             
C124                1          1 Stationery Stationery           315                         500 Stationery           Stationery         
C126                2          2 Travel     Travel|Admin         200|413                     600 Travel|Admin         Travel|Admin       
3 rows selected.
select contractid,
          case when count(distinct materialgroup) = 1 and count(materialgroup) > 1 then max(materialgroup)
          else
          rtrim(
                      xmlagg(
                              xmlelement(e, materialgroup|| '|')).extract('//text()'),'|') end materialgroup,
          rtrim(
                      xmlagg(
                              xmlelement(e, commoditycode|| '|')).extract('//text()'),'|') commoditycode,amount
        from (
        with t1 as (
        select 'C123' contractid,    'Travel' materialgroup,     200    commoditycode, 100 amount from dual union all
        select 'C123',            'Travel',    201,    100 from dual union all
        select 'C123',            'Travel',    203,    100 from dual union all
        select 'C124','Stationery',    315,    500 from dual union all
        select 'C126','Travel',    200,    600 from dual union all
        select 'C126','Admin',413,    600 from dual  )
        select * from t1)
        group by contractid,amount;
CONTRACTID MATERIALGROUP        COMMODITYCODE            AMOUNT
C123       Travel               200|203|201                 100
C124       Stationery           315                         500
C126       Travel|Admin         200|413                     600
3 rows selected.
with t1 as (
        select 'C123' contractid,    'Travel' materialgroup,     200    commoditycode, 100 amount from dual union all
        select 'C123',            'Travel',    201,    100 from dual union all
        select 'C123',            'Travel',    203,    100 from dual union all
        select 'C124','Stationery',    315,    500 from dual union all
        select 'C126','Travel',    200,    600 from dual union all
        select 'C126','Admin',413,    600 from dual  ),
        t2 as
        select contractid, materialgroup
        from t1
        group by contractid, materialgroup
select  t1.contractid,
          t2.materialgroup,
          rtrim(
                      xmlagg(
                              xmlelement(e, commoditycode|| '|')).extract('//text()'),'|') commoditycode,amount
from t1,
                select contractid,
                            rtrim(
                                  xmlagg(
                                          xmlelement(e, materialgroup|| '|')).extract('//text()'),'|') materialgroup
                from t2
                group by contractid
                ) t2
where t1.contractid = t2.contractid
group by t1.contractid, t2.materialgroup, t1.amount;
CONTRACTID MATERIALGROUP        COMMODITYCODE            AMOUNT
C123       Travel               200|203|201                 100
C124       Stationery           315                         500
C126       Admin|Travel         200|413                     600
3 rows selected.

Similar Messages

  • How to get the desired output in the format ...?

    Hi all,
    I am having data like this.
    Col1 col2 col3
    1 2 1
    1 2 2
    1 2 3
    2 3 7
    2 3 8
    2 3 9
    I want to output the data like this
    1 2 1,2,3
    2 3 7,8,9
    How to get this.
    Thanks in advance,
    Pal

    In simple sql...
    Connected to:
    Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
    With the Partitioning, OLAP and Data Mining options
    SQL> select * from t
      2  /
          COL1       COL2       COL3
             1          2          1
             1          2          2
             1          2          3
             2          3          7
             2          3          8
             2          3          9
    6 rows selected.
    SQL> select max(decode(rno,1,to_number(col1||col2||col3))) col1, max(decode(rno,2,col3)) col2, max(decode(rno,3,col3)) col3
      2    from (select row_number() over(partition by col1,col2 order by col3) rno, t.*
      3           from t)
      4  group by col1
      5  /
          COL1       COL2       COL3
           121          2          3
           237          8          9
    SQL>Thanks,
    Karthick.

  • How to get the desire output from sql query

    Consider an Order Table: ...
    Order Table:
    Order Id Item Qty
    O1 A1 5
    O2 A2 1
    O3 A3 3
    Please provide SQL which will explode the above data into single unit level records as shown below
    Desired Output:
    Order Id Order Id Qty
    O1 A1 1
    O1 A1 1
    O1 A1 1
    O1 A1 1
    O1 A1 1
    O2 A2 1
    O3 A3 1
    O3 A3 1
    O3 A3 1

    How do I ask a question on the forums?
    SQL and PL/SQL FAQ

  • How to get the Query output to Excel

    Hi ,
    Can you tell me how to get the Query output to excel with out using any third party tool?
    Can you tell me how to write the code in Webservice and call it..
    Please explain it Elaboartly..
    Thanks in Advance!!!
    Mini

    whats your source system?
    you can use Live office, or query as a webservice if you are getting data from universe
    if you're getting data from SAP BI query and you have a java stack on your netweaver then you can get the data directly using sap bi connector in xcelsius.
    good luck

  • How to correctly perform a join to get the desired output

    Hi,
    I have the following query which gives me the desired output.
    SELECT
    Cast(TEDW_F_STORE_OPS_GOAL.LOCATION_NUM As Varchar) As LOCATION_NUM,
    Cast(TEDW_D_DATE_TYPE_1.DATE_SHORT As Varchar) As DATE_SHORT,
    'Store' As DRIVER_TYPE,
    'OPS GOAL' As DRIVER,
    SUM(OPS_GOAL) As ROW_TOTAL
    FROM Planning.TEDW_F_STORE_OPS_GOAL
    left outer join
    edw.Calendar.TEDW_D_DATE_TYPE_1
    ON TEDW_F_STORE_OPS_GOAL.DATE_KEY = TEDW_D_DATE_TYPE_1.DATE_KEY
    left outer join
    [EDW].[Location].[TEDW_D_LOCATION_TYPE_1_NEW]
    ON TEDW_F_STORE_OPS_GOAL.LOCATION_NUM = TEDW_D_LOCATION_TYPE_1_NEW.LOCATION_NUM
    where TEDW_D_LOCATION_TYPE_1_NEW.LOCATION_TYPE_DESC = 'FULL PRICE STORE'
    group by
    TEDW_F_STORE_OPS_GOAL.LOCATION_NUM,
    TEDW_D_DATE_TYPE_1.DATE_SHORT
    order by LOCATION_NUM desc
    , DATE_SHORT desc
    The output of the above query will be like this
    3646 2014-04-17 Store OPS GOAL 2598.00000
    3646 2014-04-16 Store OPS GOAL 2475.00000
    3646 2014-04-15 Store OPS GOAL 2497.00000
    3646 2014-04-14 Store OPS GOAL 2691.00000
    But the problem with this query is it brings back the OPS Goal for all the dates,but i have to limit the OPS goals to some particular date range which must match to this table Staging.TEDW_S_EMPOWER.So,I made the above query join to this table like this
    SELECT
    Cast(TEDW_F_STORE_OPS_GOAL.LOCATION_NUM As Varchar) As LOCATION_NUM,
    Cast(TEDW_D_DATE_TYPE_1.DATE_SHORT As Varchar) As DATE_SHORT,
    'Store' As DRIVER_TYPE,
    'OPS GOAL' As DRIVER,
    SUM(OPS_GOAL) As ROW_TOTAL
    FROM Planning.TEDW_F_STORE_OPS_GOAL
    left outer join
    edw.Calendar.TEDW_D_DATE_TYPE_1
    ON TEDW_F_STORE_OPS_GOAL.DATE_KEY = TEDW_D_DATE_TYPE_1.DATE_KEY
    left outer join
    [EDW].[Location].[TEDW_D_LOCATION_TYPE_1_NEW]
    ON TEDW_F_STORE_OPS_GOAL.LOCATION_NUM = TEDW_D_LOCATION_TYPE_1_NEW.LOCATION_NUM
    left outer join
    Staging.TEDW_S_EMPOWER
    on TEDW_D_DATE_TYPE_1.DATE_SHORT = TEDW_S_EMPOWER.DATE_SHORT
    and TEDW_F_STORE_OPS_GOAL.LOCATION_NUM = TEDW_S_EMPOWER.LOCATION_NUM
    where TEDW_D_LOCATION_TYPE_1_NEW.LOCATION_TYPE_DESC = 'FULL PRICE STORE'
    group by
    TEDW_F_STORE_OPS_GOAL.LOCATION_NUM,
    TEDW_D_DATE_TYPE_1.DATE_SHORT
    having TEDW_D_DATE_TYPE_1.DATE_SHORT between MIN(TEDW_S_EMPOWER.date_short) and MAX(TEDW_S_EMPOWER.date_short)
    order by LOCATION_NUM desc
    , DATE_SHORT desc
    Now the output of this query will be like this
    3646 2014-04-17 Store OPS GOAL 7794.00000
    3646 2014-04-16 Store OPS GOAL 7425.00000
    3646 2014-04-15 Store OPS GOAL 7491.00000
    3646 2014-04-14 Store OPS GOAL 8073.00000
    If you can observe the OPS Goal Sum values have changed drastically, i was able to limit the date range i wanted but now i dont get the correct OPS Goal values.
    Can someone please help me with this?
    Thanks

    Hi RJP,
    Yes you are absolutely correct, in the "Staging.TEDW_S_EMPOWER"
    we have 3 rows for every date and location,so i changed my second sql to be something like this
    SELECT
    Cast(TEDW_F_STORE_OPS_GOAL.LOCATION_NUM As Varchar) As LOCATION_NUM,
    Cast(TEDW_D_DATE_TYPE_1.DATE_SHORT As Varchar) As DATE_SHORT,
    'Store' As DRIVER_TYPE,
    'OPS GOAL' As DRIVER,
    SUM(OPS_GOAL) /3 As ROW_TOTAL
    FROM Planning.TEDW_F_STORE_OPS_GOAL
    cross join
    EDW.Utility.TEDW_J_PROCESS_DATE
    inner join
    edw.Calendar.TEDW_D_DATE_TYPE_1
    ON TEDW_F_STORE_OPS_GOAL.DATE_KEY = TEDW_D_DATE_TYPE_1.DATE_KEY
    left outer join
    [EDW].[Location].[TEDW_D_LOCATION_TYPE_1_NEW]
    ON TEDW_F_STORE_OPS_GOAL.LOCATION_NUM = TEDW_D_LOCATION_TYPE_1_NEW.LOCATION_NUM
    left outer join
    Staging.TEDW_S_EMPOWER
    on TEDW_D_DATE_TYPE_1.DATE_SHORT = TEDW_S_EMPOWER.DATE_SHORT
    and TEDW_F_STORE_OPS_GOAL.LOCATION_NUM = TEDW_S_EMPOWER.LOCATION_NUM
    where TEDW_D_LOCATION_TYPE_1_NEW.LOCATION_TYPE_DESC = 'FULL PRICE STORE'
    group by
    TEDW_F_STORE_OPS_GOAL.LOCATION_NUM,
    TEDW_D_DATE_TYPE_1.DATE_SHORT
    having TEDW_D_DATE_TYPE_1.DATE_SHORT between MIN(TEDW_S_EMPOWER.date_short) and MAX(TEDW_S_EMPOWER.date_short)
    order by LOCATION_NUM desc
    , DATE_SHORT desc
    Now i receive the correct values as i am doing divided
    by 3,but may be in the future the empower tablemay have more than 3 ,is there any other effective way i can do this?
    below is the sample query and sample data from empower table.
    select * from Staging.TEDW_S_EMPOWER
    where DATE_SHORT = '2014-04-17'
    and LOCATION_NUM = 3020
    DRIVER_TYPE DRIVER DATE_SHORT
    store Sales 2014-04-17
    store Transactions 2014-04-17
    store Traffic 2014-04-17
    Thanks

  • How to get the job output to be displayed/send in a report?

    Dear All,
    IHAC that have a couple of jobs which they all work fine and return the desired value, and now the customer wants to take the output of the jobs and place it in one big report?
    The jobs created are the daily health checks that the DBAs run. They would like to have all the output from all the jobs consolidated in one report to be sent to them every morning on their emails.
    Kindly advise if this is doable.

    There isn't really a way to redirect a job's output. Unless you try to dig it out of the repository. Trust me it will be a hell of a job to puzzle out the locations and SQL statements to get it.
    You might consider trying to migrate your jobs into reports (if possible). Reports can be redirected to e-mail recipients.
    Regards
    Rob

  • How to get the given output format..

    Hi,I want to write a code in ABAP in such a way that I should get the output in the right side format.
    Ex:
    1200 - > 1,200
    12000  - > 12,000
    120000 ->  120,000
    1200000 -> 1,200,000
    12000000 -> 12,000,000
    120000000 - > 120,000,000
    Thanks.

    HI tushar,
    1. I don't know whether i understood u r question !
    2. FOr writing with COMMA,
      if we use simple WRITE,
      then it will show just as u want !
    regards,
    amit m.

  • How to modify this query to get the desired output format

    I hv written a Query to display all the parent table names and their primary key columns(relevant to this foreign key of the child table).The query is given below...
    SELECT DISTINCT(TABLE_NAME) AS PARENT_TABLE,COLUMN_NAME AS PARENT_COLUMN
    FROM ALL_CONS_COLUMNS
    WHERE CONSTRAINT_NAME IN (SELECT AC.R_CONSTRAINT_NAME
    FROM ALL_CONSTRAINTS AC
    WHERE AC.TABLE_NAME=TABLE_NAME
    AND AC.TABLE_NAME='&TABLE'
    AND AC.R_CONSTRAINT_NAME IS NOT NULL);
    This query will display all the parent tables and their primary key columns.Now my problem is that how to modify this query to also display the foreign key column name of the child table.
    I want the query result in the following format.The query should display the following columns.1)child table's name,2)child table's foreign key column name,3)the corresponding parent table's name,4)the parent table's primary key column name(which is the foreign key in the child table).
    For Example I want the output as follows...
    TAKE THE CASE OF SCOTT.EMP(AS INPUT TO YOUR QUERY)
    CHILD_TABLE CHILD_COLUMN PARENT_TABLE PARENT_COLUMN
    EMP DEPTNO DEPT DEPTNO
    In this result I hv used alias name for the columns.The query should display this only for the foreign keys in the child table.In the query which I sent to you earlier will give the parent table and the parent column names,But I also want to append the child table and child column names there.
    any help on how to tackle would be appreciated.

    Try this query
    SELECT c.table_name child_table,
         c.column_name child_column,
         p.table_name parent_table,
         p.column_name parent_column
    FROM user_constraints a,user_constraints b,user_cons_columns c,
         user_cons_columns p
    WHERE a.r_constraint_name=b.constraint_name and
          a.constraint_name=c.constraint_name and
          b.constraint_name=p.constraint_name and
          c.position=p.position
    ORDER BY c.constraint_name,c.position
    Anwar

  • How to get the desired total of Random numbers ?

    I m in a big problem and want a urgent solution.
    I want to randomise numbers with specified limit and the total of all the randomised numbers should be desirable.
    e.g. if i m generating random number 24 times in a loop then the total of all the gerenrated numbers should be 100 and each randomised generated number should not be greater than 6.
    Please help me out. is there any method from which i can get, desirable total from the gererated random numbers ?
    Please help.
    thanks in advance

    In my usual manner, I'll throw in a couple of ideas and leave others to discard them again :-)
    Pick random numbers. If, at some point, the sum goes over 100, throw away the last number at instead put in the number that will make the sum exactly 100. Then put in 0 until you have 24 numbers. Those 0s won't look random. If it helps, shuffle all the numbers so the 0 come in random places in the sequence. If it's still not random enough, discard the whole idea. If, on the other hand, you still are m numbers short of 24 numbers and the sum goes under 100 - (m * 6), in a similar manner stop using randomness and throw in the numbers needed to hit 100. Shuffle to distribute the 6s.
    Another idea, there are 100 ^ 24 or 10 ^ 48 ways to put 100 balls into 24 buckets. Find out how many ways there are under the constraint that you can put at most 6 balls into a bucket. Enumerate them, pick one at random and generate it. I would say that this should give you a good randomness, but does it also look that way under your requirements?

  • GETTING NO ERROR BUT STILL NOT GETTING THE DESIRED OUTPUT!!!!!!!!

    HIII ,
    AM DOING AN APPLICATION IN WHICH I AM TRYING TO INSERT VALUES IN A TABLE(CREATED THRU JAVA DICTIONARY), USING EJBS(ENTITY BEAN AND SESSION BEAN) AND COMMAND BEAN..AND WEBDYNPRO....
    AFTER DEPLOYMENT EVRYTHNG IS RUNNING FINE BUT VALUES NOT GETTING ADDED IN THE TABLE...
    THE CODE FOR THE "ADD" BUTTON IS :
    wdContext.currentEmp_cmdElement().modelObject().add(wdContext.currentEmp_cmdElement().getEmpno(),wdContext.currentEmp_cmdElement().getEmpname());
    THE CODE FOR ADD function IN COMMANDBEAN IS
    public void add(String empno,String empname){
    try {
    local.createdata(empno,empname);
    } catch (Exception e) {
    e.printStackTrace();}
    PLZZ DO HELP OUT!!!

    try { aPreparedStatement.close();
               if(dmd!=null)
                            dmd = null;
               if(con!=null)
                            con.close();
                catch (Exception e)
                     e.printStackTrace();  
                }instead of catching the last error i printed it and it came up with an error of nullPointerException
    for the line of code
    try { aPreparedStatement.close();how can i fix this error please
    and thank you

  • How to Get the desired Name in Distrubution Lists

    Hai all.
    In my scenario I come accross distrubution list.
    I created sucessfully Distrubution Lists and validated and run in Ofline Wizard and it run sucessfully.
    But here comes the issue is the name of the report is which created by distrubution list is appeneded with the username)description of report)and name of report.
    but i need a anme in another format can any one help me out....
    thanks,
    Rajesh

    Hi,
    Variants are stored in table VARI and VARID.
    You can use RS_ALL_VARIANTS_4_1_REPORT to get all the variants for a report program.
    please check out the link below it will be helpful to you
    Re: Programs for a transaction variant
    Hope this helps.
    ashish

  • To write a single query to get the desired output.

    Hi,
    I have table by name "employees" it contains 20 records meaning 20 employee details.
    some of the column it contains are employee_id,Hiredate as below.
    EMPLOYEE_ID|HIRE_DATE
    100|6/17/1987
    101|9/21/1989
    102|1/13/1993
    103|1/3/1993
    104|5/21/1991
    107|2/7/1999
    124|11/16/1999
    141|10/17/1995
    142|1/29/1997
    143|3/15/1998
    144|7/9/1998
    149|1/29/2000
    174|5/11/1996
    176|3/24/1998
    178|5/24/1999
    200|9/17/1987
    201|2/17/1996
    202|8/17/1997
    205|6/7/1994
    206|6/7/1994
    The query should display the total number of employees, employees hired in 1995,1996,1997 and 1998 some thing like below.
    output
    Total     1995     1996     1997     1998
    20     1     2     2     3
    please let me know the query.
    Thanks
    Dinesh

    SQL> select * from employees;
             EMPLOYEE_ID HIRE_DATE
                     100 17-JUN-1987 00:00:00
                     101 21-SEP-1989 00:00:00
                     102 13-JAN-1993 00:00:00
                     103 03-JAN-1993 00:00:00
                     104 21-MAY-1991 00:00:00
                     107 07-FEB-1999 00:00:00
                     124 16-NOV-1999 00:00:00
                     141 17-OCT-1995 00:00:00
                     142 29-JAN-1997 00:00:00
                     143 15-MAR-1998 00:00:00
                     144 09-JUL-1998 00:00:00
                     149 29-JAN-2000 00:00:00
                     174 11-MAY-1996 00:00:00
                     176 24-MAR-1998 00:00:00
                     178 24-MAY-1999 00:00:00
                     200 17-SEP-1987 00:00:00
                     201 17-FEB-1996 00:00:00
                     202 17-AUG-1997 00:00:00
                     205 07-JUN-1994 00:00:00
                     206 07-JUN-1994 00:00:00
    20 rows selected.
    SQL> select count(*) total_employees
      2        ,sum(case when to_char(hire_date,'YYYY') = '1995' then 1 else 0 end) hired_1995
      3        ,sum(case when to_char(hire_date,'YYYY') = '1996' then 1 else 0 end) hired_1996
      4        ,sum(case when to_char(hire_date,'YYYY') = '1997' then 1 else 0 end) hired_1997
      5        ,sum(case when to_char(hire_date,'YYYY') = '1998' then 1 else 0 end) hired_1998
      6  from   employees;
         TOTAL_EMPLOYEES           HIRED_1995           HIRED_1996           HIRED_1997           HIRED_1998
                      20                    1                    2                    2                    3Edited by: SomeoneElse on Jan 6, 2009 8:09 AM

  • How to get the following output

    Table 1                                        Table 2    
    EmpCode    EmpName        EmpCode EmpPhone
    10001         ABC                    10001    12345
    10002         BCD                    10001    23456
    10003         CDE                    10001    34567
    10004         EFG                     10006    45678
    10005         FGH                     10007    56789
    10006         GHI                     10007    67890
    10007         HIJ                      10010    78901
    10008         IJK                      10010    89012
    10009         JKL                     10010    90123
    10010         KLM                    10011    13579
    10011         LMN                    10012    35791
    10012         MNO                   10012    57913
    10013         NOP                   10012    79135
    10014         OPQ                   10017    91357
    10015         PQR                    10017    12390
    10016         QRS                    10019    23479
    10017         RST            
    10018         STU            
    10019         TUV  
    output        
    EmpCode    EmpName    EmpPhone
    10001           ABC             12345/23456/34567
    10002           BCD    
    10003          CDE    
    10004          EFG    
    10005          FGH    
    10006         GHI            45678
    10007         HIJ           56789/67890
    10008         IJK    
    10009         JKL    
    10010         KLM       78901/89012/90123
    10011         LMN      13579
    10012         MNO       35791/57913/79135
    10013         NOP    
    10014        OPQ    
    10015        PQR    
    10016       QRS    
    10017       RST       91357/12390
    10018       STU    
    10019       TUV      23479
                              

    Srimanta,
    Check this:
    select t1.EmpCode,t1.EmpName,STUFF((select '/'+EmpPhone from Table2 where EmpCode=t1.EmpCode for xml path('')),1,1,'') as PhoneNum
    from Table1 t1
    left join Table2 t2 on t1.EmpCode=t2.EmpCode
    group by t1.EmpCode,t1.EmpName
    Edited : small change in code(highlighted - t1 instead of t2)
    Thanks,
    Jay
    <If the post was helpful mark as 'Helpful' and if the post answered your query, mark as 'Answered'>

  • Getting the desired Output

    Hi ALl,
    I have a table as Listed below.
    SQL> CREATE  TABLE T1 (c1 varchar2(10),c2 varchar2(10),c3 varchar2(10), c4 var
    ar2(10),audit1 number);
    Table created.
    SQL> DESC T1
    Name                                      Null?    Type
    C1                                                 VARCHAR2(10)
    C2                                                 VARCHAR2(10)
    C3                                                 VARCHAR2(10)
    C4                                                 VARCHAR2(10)
    AUDIT1                                             NUMBER
    SQL> INSERT INTO T1 VALUES('A','B',NULL,2,1);
    1 row created.
    SQL> INSERT INTO T1 VALUES('A','B',1,NULL,1);
    1 row created.
    SQL> COMMIT;
    Commit complete.
    SQL> SELECT * FROM T1;
    C1         C2         C3         C4             AUDIT1
    A          B                     2                   1
    A          B          1                              1
    SQL>I need to output from the above table as single row considering the Dupilcate values as once row ,and also nned to neglect the Null values from it and take the other possible value in it.
    C1         C2         C3         C4             AUDIT1
    A          B           1          2                   1

    Suppose a new row(below) is added, what do you expect as o/p?
    INSERT INTO T1 VALUES('A','B',1,3,2);Purvesh's query will give you the <tt>MAX(c4)</tt> but if you use <tt>SUM(c4)</tt> it'll also give you a single-row & NULLS removed but the values summed.
    -- "Query 1"
    select c1, c2, max(c3) c3, max(c4) c4, max(audit1) audit1
      from t1
    group by c1, c2;
    A     B     1     3     2
    -- "Query 2"
    select c1, c2, SUM(c3) c3, SUM(c4) c4, SUM(audit1) audit1
      from t1
    group by c1, c2;
    A     B     3     7     6Please clarify this.

  • How to get the console output generated by a executable program?

    when I am trying to use method getOutputSteam of Process to gain the outputStream,I got nothing!
    I have also tried to use stream redirect,also no result!
    please help me! Thank you in advance!
    my main code are below:
    Process ps=Runtime.getRuntime().exec("xxx.exe");/*xxx.exe is a executable program which will generate a console with the message I want to gain.*/
    int exitVal= ps.waitFor();
    if(exitVal==0){
    BufferredReader br = new BufferedReader(new InputStreamReader(ps.getInputStream()));               String st;
    while((st = br.readLine()) !=null){
    System.out.println("write:"+st);
    }//my result show that I got nothing from the progam.
                                                           }

    I've seen this kind of problem with an offending xxx.exe. Generally it means that the program isn't flushing its output immediately, so your java program never sees it.

Maybe you are looking for

  • Keep getting error message while instaling software updates

    i just receive my imac from apple store after they fix my HDD , my imac is using version 10.6.8 and have 2.66 GHz intel core i5 prossesor also have memory 12 GB 1067 MHz DDR3 , i had problem before with my imac and i sent it to apple store to fix it

  • List item - Population - Based on Data setup

    Dear All, I need to populate the list item based on data defined at the database level. Tables Used: Table 1 : JBCAI_JOB_COM_ADD_INFO Column Name     Pk     Null?     Data Type     Default      JBEDC_UID          1     N     NUMBER (22)           JBC

  • Mail Service Keeps Stopping For No Reason

    Hi There everyone. Over the past few days my Mail Service keeps stopping. Not giving any particular error, the only clue is this log message:- Jan 6 13:12:39 server master[371]: exiting on SIGTERM/SIGINT Is that helpful? I can start the service again

  • Installing Lightrom 4 without a CD Rom

    Using a PC. have lightroom 4 and would like to install it there but do not have a CD ROM on the new machine.  Is there a way to add Lightroom to the new computer via download and by using the serial key I have?

  • MTA shows "post office now closed/open"

    Hi, after updating agents from 8.0.2 to 8.0.3 I have MTA showing "post office now closed" and right after it "post office now open" repeated with some interval, every half an hour approx. This happens on all 5 servers (NetWare 6.5 sp8) which were upd