Combine multiple rows of table in single row

Hi Experts,
I have a table of below format.
MSDNID
WALL_BAL
WALL_DATE
123
34
06-Sep-13
123
56
07-Sep-13
123
78
08-Sep-13
123
65
09-Sep-13
123
34
10-Sep-13
123
87
11-Sep-13
Now I have to create a new table. which should contain unique MSDNID with WALL_BAL in different column .
Like below
MSDNID
DAY1_BAL
DAY2_BAL
DAY3_BAL
DAY4_BAL
DAY5_BAL
DAY6_BAL
123
87
34
65
78
56
34
How can I write a query for this?

in 10g , you can use something like
select MSDNID,
max(decode(WALL_DATE, '11-Sep-13', WALL_BAL, null) day_1_bal,
max(decode(WALL_DATE, '06-Sep-13', WALL_BAL, null) day_6_bal
from t
group by MSDNID;
But it only works if you have limited # of days.

Similar Messages

  • Combine multiple rows in single row

    I am new to SQL server and i am trying to combine multiple row in single row but i am not able to do it.Can anyone help me out?
    Input :
    Id |RED |BUY |BSW
    1328 NULL NULL 0.05
    1328 NULL 0.06 NULL
    1328 0.01 NULL NULL
    1328 0.05 NULL NULL
    1329 NULL NULL 0.05
    1329 NULL 0.05 NULL
    1329 0.05 NULL NULL
    Output
    Id |RED |BUY |BSW
    1328 0.01 0.06 0.05
    1328 0.05 NULL NULL
    1329 0.05 0.05 0.05

    Actually I am consolidating above result into text file and sending it to external system.Main aim is to remove NULL values and arrange the data as expected output.
    Also expected output can be
    Id         |RED   
    |BUY    |BSW
    1328        0.05   
    0.06    0.05
    1328        0.01   
    NULL    NULL
    Or
    Id         |RED   
    |BUY    |BSW
    1328        0.01   
    0.06    0.05
    1328        0.05   
    NULL    NULL
    for Id= 1328.

  • How do i combine multiple pdf file into a single pdf file?

    how do i combine multiple pdf files into a single pdf file?

    The thread was started in early March and it's Mid-April, I know this very well. The OP of this thread posted a very common and simple question or maybe he/she would have resolved this. For an Adobe Acrobat user it's not at all difficult to combine multiple PDF files into one. But to combine PDF files full version of Adobe Acrobat is mainly required, otherwise PDF files can't be combined. For example, I'm using Adobe Acrobat 9 Pro. These simple steps are mainly required to combine PDF files:
    Open Adobe Acrobat.
    Click on Combine and click on Merge files into a single PDF.
    A window will be appearing, click on Add Files and select the PDF files you want to combine.
    Arrange the selected files in any order with the help of Move Up and Move Down button.
    Now click on Combine File and the selected PDF files will be combined within a few seconds.
    A new PDF file will be created. Click on Save As and name this new PDF file. Then, click on Save.
    A new PDF file will be created and all the selected PDF files are combined in it. The steps shown above might be different in other versions of Adobe Acrobat. Other than this, some third-party PDF merge software are also available. Most of them are available with a demo version for free evaluation. I've heard much about SysInfoTools PDF Merge software on other forums and directories and it's demo version is freely available. One may check its demo version if Adobe Acrobat (full version) is not available.
    Regards

  • How to combine multiple Unmanaged Solution to one single Managed solution

    Hi,
    How to combine multiple Unmanaged Solution to one single Managed solution.?
    There were some other third party developer have kept things lik ein UAT there are 2 release solution and both are Managed Solution.
    And in Production the changes are only deployed for release 1 and for the release 2 changes deployment needs to be done.
    But when i import that second release Managed Solution from UAT to Production then i got number of elements missing but i have checked they are already there in Soolution.
    I did some R&D on this but not much helpful.
    I thought i require to convert Unmanaged Solution of Production environment to Managed first for first release and then needs to import Managed solution of UAT to Production for second release.
    Is this the right way to overcome form this situation?
    Any help and response would be really appreciated.
    Thanks.
    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    Hi, 
    You can prepare unmanaged solution by adding all the components from the default solution,which are there in the managed solution, If Customizatiable entity is true in  the managed solution.

  • Combining multiple rows to singe row thru SQL Stmt

    Hello,
    I am trying to combine values returned from multiple row into one row,
    thru inner/outer sql or any optimal way.
    In the example i would like to have First name, Last name, email and phone to be
    returned as a single row.
    create table TEMP_AAAAA
      FIRST_NAME VARCHAR2(25),
      LAST_NAME  VARCHAR2(25),
      CON_METHOD VARCHAR2(25),
      CON_VALUE  VARCHAR2(25)
    INSERT INTO TEMP_AAAAA VALUES('TOM','MAC','EMAIL','[email protected]');
    INSERT INTO TEMP_AAAAA VALUES('TOM','MAC','PHONE','12345');Any suggestion in doing it thru sql stmt.
    I have done this thru pl/sql, wondering if this could be achieve thru single SQL Stmt
    DECLARE
    v_FIRST_NAME  VARCHAR2(25);
    v_SECOND_NAME VARCHAR2(25);
    v_EMAIL       VARCHAR2(25);
    v_PHONE       VARCHAR2(25);
    BEGIN
    v_FIRST_NAME := NULL;
    v_SECOND_NAME := NULL;
    v_EMAIL := NULL;
    v_PHONE := NULL;
    FOR IMPL_CUR IN(SELECT * FROM TEMP_AAAAA ORDER BY CON_METHOD DESC)
    LOOP
            IF v_FIRST_NAME IS NULL
            THEN
               v_FIRST_NAME := IMPL_CUR.FIRST_NAME;
            END IF;
            IF v_SECOND_NAME IS NULL
            THEN
               v_SECOND_NAME := IMPL_CUR.LAST_NAME;
            END IF;  
            IF v_PHONE IS NULL AND IMPL_CUR.CON_METHOD = 'PHONE'
            THEN
               v_PHONE := IMPL_CUR.CON_VALUE;
            END IF;
            IF v_FIRST_NAME = IMPL_CUR.FIRST_NAME AND
               v_SECOND_NAME = IMPL_CUR.LAST_NAME AND
               length(v_PHONE) > 0
            THEN
              IF v_EMAIL IS NULL AND IMPL_CUR.CON_METHOD = 'EMAIL'
              THEN
                 v_EMAIL := IMPL_CUR.CON_VALUE;
                 EXIT;
              END IF;       
            END IF;
    END LOOP;
             DBMS_OUTPUT.put_line('firstName...:' || v_FIRST_NAME);    
             DBMS_OUTPUT.put_line('lastName....:' || v_SECOND_NAME);    
             DBMS_OUTPUT.put_line('PHONE.......:' || v_PHONE);
             DBMS_OUTPUT.put_line('EMAIL.......:' || v_EMAIL);
    END;

    Hi Ludy,
    Following query should work -
    P.S. - I have added records for one more person with first name as 'TOM1' and last name as 'MAC1' for testing purpose. Given inserts for these 2 records as well.
    Connected to Oracle Database 11g Release 11.2.0.1.0
    SQL>
    SQL> INSERT INTO TEMP_AAAAA VALUES('TOM1','MAC1','EMAIL','[email protected]');
    1 row inserted
    SQL> INSERT INTO TEMP_AAAAA VALUES('TOM1','MAC1','PHONE','12345');
    1 row inserted
    SQL>
    SQL>
    SQL> SELECT t.first_name
      2        ,t.last_name
      3        ,MAX(decode(t.con_method, 'PHONE', t.con_value, NULL)) phone
      4        ,MAX(decode(t.con_method, 'EMAIL', t.con_value, NULL)) email
      5    FROM temp_aaaaa t
      6   GROUP BY t.first_name
      7           ,t.last_name
      8  /
    FIRST_NAME     LAST_NAME   PHONE   EMAIL
    TOM            MAC         12345   [email protected]
    TOM1           MAC1        12345   [email protected]
    SQL> Hope this helps.
    Cheers,
    - Anirudha
    Edited by: Anirudha Dhopate on Nov 10, 2011 9:12 PM

  • How can I combine multiple icloud calendars into a single published calendar?

    I have several calendars in Ical where I map my activities and schedules. Like many I need several calendars to categorise events.
    Now, I'd like others to see when I'm free and when I'm unavailable. For this, I'd need to find a way to copy multiple Icloud calendars into a single one for publishing - and the published calendar would also have to sync to any update I make in the original calendar.
    Any way to make this happen? Any third party app? Tried a couple - they were outdated and / or cumbersome.
    If only there was a "smart calendar" tool in Ical …

    It worked - up to the crucial point: after combining icloud calendars into one "on the machine" calendar, the latter is ready for going public. But of course - this public calendar will only contain the .ics files and will not sync for updates from the icloud calendars.
    And that's what I want.
    If this problem is not possible to solve with the software available in the Mac - is there any known third party solution for this?
    (Apple: "smart calendars" please!)

  • Can you combine multiple itunes accounts into a single one?

    I set up separate itunes accounts for my (2) sons (8 & 10) because one had an iPod and the other had an iTouch. 
    They just got an iPad for X-mas (that they'll share) ... I want to set up the iCloud and create a "joint" account. 
    Is it possible to combine their multiple itunes acounts into a single account?

    This is all i know but all you can do is just creat a new one for them both and send all the stuff to the one think u can do that i hope it helps

  • Combine multiple sales order in a single delivery

    Hi Experts,
    As per standard SAP we have a facility to combine multiple sales order in one delivery  if orders have same shipping point,ship to party & delivery date.
    But we have a requirement that the orders should get combine in a delivery only when shippping point,ship to party,delivery date & pricing date are same for orders.
    Please let me know is there is any standard config available or do we need to write any exits & so...
    Please reply ASAP .

    Hi,
         I think this is not there in standard functionality.
          In this case you need to go for user exit for delivery routine 101, include program FV50B101
    Check delivery routine 101 in VOFM and with the help of your abap consultant this can be done.
    Thanks,
    Swamy H P

  • Combining Multiple Rows into single row with multple columns

    Hi Experts,
    I have the following requirement, kindly help me.
    I have data in my table like below.
    ID NAME DEPT
    1 Sam 10
    1 Sam 20
    2 alex     30
    2 alex 40
    2 alex 50
    3 vinod 60
    3 vinod 70
    I want to show the same data into single row with dynamically generating columns for DEPT. I want show like below.
    ID NAME DEPT1 DEPT2 DEPT3
    1 Sam 10 20
    2 alex 30 40 50
    3 vinod 60 70
    It's urgent requirement, kindly help me.
    Thanks in advance.

    Right I've had my drink, so what was this "urgent" question then?
    798616 wrote:
    I have data in my table like below.
    ID NAME DEPT
    1 Sam 10
    1 Sam 20
    2 alex     30
    2 alex 40
    2 alex 50
    3 vinod 60
    3 vinod 70
    I want to show the same data into single row with dynamically generating columns for DEPT. I want show like below.Dynamic numbers of columns eh! Tricky.
    If you understand how SQL statements are executed it's along these lines...
    1. Open Cursor
    2. Parse SQL statement and determine columns
    3. Bind in any input values
    4. Fetch data
    5. Bind out values to columns
    6. Repeat step 3 until no more data
    7. Close cursor
    Now, you're expecting that you can determine the columns (step 2) from the fetched data (step 4 onwards). You can't. The SQL engine needs to know the expected columns before any data is fetched so, it can't base the number of columns on the data itself.
    If you need that requirement, you would need to query the data first and build up a dynamic query based on the data and then execute that dynamically built query to fetch the data and pivot it into those columns, which means that you have queried the data twice. Not good practice and not good (or simple) coding.
    What you're talking of doing is something that should be handled at the presentation/interface layer, not as part of the data fetch.
    Typically these sorts of things are handled most easily in report generation/writer tools such as Oracle Reports, Business Objects etc. where they fetch the data from the database and then process it to format it on the display, pivoting the results as required.
    It's not something that lends itself to be easily achieved in SQL. Yes, SQL can do pivoting of data quite easily, but NOT with a dynamic number of columns.
    If you were to specify that there is a maximum number of columns that you could get (rather than wanting it dynamic), then you can do it simply in SQL with the max-decode method...
    SQL> ed
    Wrote file afiedt.buf
      1  with t as (select deptno, ename, row_number() over (partition by deptno order by ename) as rn from emp)
      2  --
      3  select deptno
      4        ,max(decode(rn,1,ename)) as ename1
      5        ,max(decode(rn,2,ename)) as ename2
      6        ,max(decode(rn,3,ename)) as ename3
      7        ,max(decode(rn,4,ename)) as ename4
      8        ,max(decode(rn,5,ename)) as ename5
      9        ,max(decode(rn,6,ename)) as ename6
    10        ,max(decode(rn,7,ename)) as ename7
    11        ,max(decode(rn,8,ename)) as ename8
    12        ,max(decode(rn,9,ename)) as ename9
    13        ,max(decode(rn,10,ename)) as ename10
    14  from t
    15  group by deptno
    16* order by deptno
    SQL> /
        DEPTNO ENAME1     ENAME2     ENAME3     ENAME4     ENAME5     ENAME6     ENAME7     ENAME8     ENAME9     ENAME10
            10 CLARK      KING       MILLER
            20 ADAMS      FORD       JONES      SCOTT      SMITH
            30 ALLEN      BLAKE      JAMES      MARTIN     TURNER     WARD
    SQL>

  • Combining multiple rows into a single row

    Hi all,
    I have a tricky situation in a HR select.
    Imagine I have a dataset as below, simplified of course.
    Name Start Date End date Job Title Salary
    Tom 01/01/07 02/03/08 Gopher £500
    Tom 03/03/08 jobsworth £600
    Rick 04/05/09 Painter £500
    Harry 02/06/07 02/06/08 Gardener £300
    Harry 03/06/08 03/06/09 Runner £200
    Harry 04/06/09 Cook £400
    now, I need to select from above and return 3 rows so it looks as below
    name start date enddate title salary start date enddate title salary start date enddate title salary etc etc
    tom 01/01/07 02/03/08 gopher £500 03/03/08 blah 600
    Rick 04/05/09 painter £500
    harry etc etc etc
    Now, I know how to select onto one row ok, asumming that each employee has a fixed number of roles but the problem is that each employee has a different number of jobs, one could have had 5 while another 50 and I do not know the maximum at this time.
    Anyone have any ideas on how to appraoch this?
    tia,
    dw
    Edited by: derrywriter on Oct 2, 2009 3:50 PM
    Edited by: derrywriter on Oct 2, 2009 3:54 PM

    Ideally this should be done in a suitable reporting tool.
    Standard SQL requires a deterministic number of columns to be known at parse time i.e. before the data is fetched it needs to know how many columns are being returned.
    If you know there is a fixed maximum to the number of columns that can be returned you can use one of the various pivot methods (search the forum) which differ depending on whether you're using 9i, 10g or 11g database.
    If you can't determine a maximum number of columns you're pretty much stuck, unless you want to write some clever interfacing to the oracle ODCI as demonstrated in this thread:
    How to pipeline a function with a dynamic number of columns?
    Personally, I believe such reporting styles should be reserved for reporting tools.

  • HOW TO COMBINE MULTIPLE ROWS INTO SINGLE ROWS

    Hi,
    I have a table with the following data:
    CASE-1
    TABLE -X
    RNO      FROM_SQN     TO_SQN     DATE
    ==========================================
    991      9           11     2010-01-01
    991      11           22     2010-01-01
    991      22           33     2010-01-01
    992      33           44     2010-01-01
    I want to see the result data as follows:
    RNO      FROM_SQN     TO_SQN     DATE
    ==========================================
    991      9           44     2010-01-01
    CASE-2
    TABLE -X
    RNO      FROM_SQN     TO_SQN     DATE
    ==========================================
    991      9           11     2010-01-01
    991      15           22     2010-01-01
    991      22           34     2010-01-01
    992      33           44     2010-01-01
    I want to see the result data as follows:
    RNO      FROM_SQN     TO_SQN     DATE
    ==========================================
    991      9           11     2010-01-01
    991      15           44     2010-01-01
    Please help me how to achieve this using SQL.
    Edited by: 986725 on Feb 7, 2013 2:36 AM

    with x as
    select 991 rno, 9 from_sqn ,11 to_sqn ,to_date('2010-01-01','yyyy-mm-dd') dt
    from dual union all
    select 991, 15 ,22 ,to_date('2010-01-01','yyyy-mm-dd') from dual union all
    select 991, 22 ,33 ,to_date('2010-01-01','yyyy-mm-dd') from dual union all
    select 991, 33 ,44 ,to_date('2010-01-01','yyyy-mm-dd') from dual
    x_with_group as
    select rno,from_sqn,to_sqn,dt,
           sum(sm) over(partition by rno,dt order by from_sqn) sm
    from
      select rno,from_sqn,to_sqn,dt,
             from_sqn-
              nvl(lag(to_sqn) over(partition by rno,dt order by from_sqn),0) sm
      from x
    select rno,min(from_sqn) from_sqn,max(to_sqn) to_sqn,dt
    from x_with_group
    group by rno,dt,sm
    order by rno,dt,from_sqn;
    RNO FROM_SQN TO_SQN DT       
    991        9     11 01-jan-2010
    991       15     44 01-jan-2010 Edited by: jeneesh on Feb 7, 2013 4:59 PM
    Assumed the date values are actually DATE types.
    Partition on DT and RNO can be amended as per your requirement..
    And assumed your sample data has a typo..
    If your data is correct..
    with x as
    select 991 rno, 9 from_sqn ,11 to_sqn ,to_date('2010-01-01','yyyy-mm-dd') dt
    from dual union all
    select 991, 15 ,22 ,to_date('2010-01-01','yyyy-mm-dd') from dual union all
    select 991, 22 ,33 ,to_date('2010-01-01','yyyy-mm-dd') from dual union all
    select 992, 33 ,44 ,to_date('2010-01-01','yyyy-mm-dd') from dual
    x_with_group as
    select rno,from_sqn,to_sqn,dt,
           sum(sm) over(order by from_sqn) sm
    from
      select rno,from_sqn,to_sqn,dt,
             from_sqn-
              nvl(lag(to_sqn) over(order by from_sqn),0) sm
      from x
    select min(rno) rno,min(from_sqn) from_sqn,max(to_sqn) to_sqn,min(dt) dt
    from x_with_group
    group by sm
    order by rno,dt,from_sqn;
    RNO FROM_SQN TO_SQN DT       
    991        9     11 01-jan-2010
    991       15     44 01-jan-2010 Edited by: jeneesh on Feb 7, 2013 5:14 PM

  • Combine multiple rows into single value

    I have the following results -
    id staff
    001 Joe
    001 Jim
    001 Dave
    002 Kim
    002 Pat
    002 Alan
    003 Peter
    004 Mick
    004 Paddy
    005 Steve
    005 Eric
    I want to have the results displayed as follows -
    id staff
    001 Joe,Jim,Dave
    002 Kim,Pat,Alan
    003 Peter
    004 Mick,Paddy
    005 Steve, Eric
    I have had a play about with this sort of thing before and I think SYS_CONNECT_BY_PATH will need to be used? Not really 100% sure though.
    All help will be appreciated.
    Cheers.

    Having a bit of trouble getting these solutions to work.
    Heres another example to try and show what my problem is...
    I have a table with the following -
    Region Country_name
    Britain England
    Britain Scotland
    Britain Wales
    Europe Spain
    Europe Italy
    Europe France
    Running the following Script...
    SELECT distinct region, SUBSTR (SYS_CONNECT_BY_PATH (country_name , ','), 2) csv
    FROM (SELECT region, country_name , ROW_NUMBER () OVER (partition by region ORDER BY region ) rn,
    COUNT (*) OVER (partition by region ) cnt
    FROM countries)
    WHERE rn = cnt
    START WITH rn = 1
    CONNECT BY rn = PRIOR rn + 1;
    I get the results ...
    Britain      England,Italy,Scotland
    Europe      England,Italy,France
    Britain      England,Wales,Scotland
    Britain      Spain,Wales,Scotland
    Europe      Spain,Italy,France
    Britain      Spain,Italy,Scotland
    Europe      England,Wales,France
    Europe      Spain,Wales,France
    Which is clearly wrong, I want
    Britain      England,Italy,Scotland
    Europe Spain,Italy,France
    and thats all!

  • Combining multiple rows into one row

    Hi all.
    My most humble apology for this question but solutions in previous threads did not seem to help much.
    Apparently, my account has not been verified and I am currently at home with no access to the SQL code so i can't post the actual code.
    We have this (mockup) of code
    Select S.C1, AViewSS.Study, AViewSS.SlotName, IST.TakenByDate, IST.ScannedByTime, SE.TimepointCalculation
    From IST
    INNER JOIN
    AViewSS ON IST.GroupID = AViewSS.GroupID and
    IST.SlotID = AViewSS.SlotID
    INNER JOIN
    S ON AViewSS.StudyID = S.StudyID
    INNER JOIN
    SE ON IST.Line = SE.Line and IST.SubLine = SE.SubLine and
    AViewSS.ScheduleID = SE.ScheduleID
    WHERE
    (IST.GroupID = 92) and (IST.SlotID between 1791 and 1795)
    and (AViewSS.VisitID = 137)
    The query currently returns this result set
    Col 1   Col 2   Taken Date  Date 1                Date 2               Date 3             
    Scanned DateTime
    Data    Data    3/12/2015  3/12/2015 7:22                                   
                    3/12/2015 7:22
    Data    Data    3/12/2015                            3/12/2015 8:47                         
    3/12/2015 8:47
    Data    Data    3/12/2015                                                    
    3/12/2015 9:27 3/12/2015 9:27
    Data    Data    3/22/2015                            3/22/2015 7:27        
                     3/22/2015 7:27
    Data    Data    3/22/2015
    Data    Data    4/12/2015
    Data    Data    4/12/2015
    Data    Data    4/12/2015
    You’ll notice that rows 1, 2, 3 are related as are rows 4, 5 and rows 6, 7, 8.
    This is what we ultimately want to see given the results above.
    In the report, rows 1, 2, 3 from the results should roll into one row with the ScannedByTimeStamp from each row returned by the query populating the appropriate report time column based on the value of a column in the row.
    Col 1   Col 2   Taken Date  Date 1                  Date 2                
    Date 3
    Data    Data    3/12/2015  3/12/2015 7:22    3/12/2015 8:47   3/12/2015 9:27
    Data    Data    3/22/2015                               3/22/2015 7:27  
    Data    Data    4/12/2015
    We would appreciate any guidance.

    Hi Duane,
    The table and matrix data regions can display complex data relationships by including nested tables,matrices, lists, charts and gauges. Tables and matrices have a tabular layout and their data comes from a single dataset, built on a single data source. The
    key diference between tables and matrices is that tables can include only row groups, where as matrices have row groups and columns groups.
    All Code in this sample are downloadable from
    this URL
    create procedure spMultiple
    as
    begin
    declare @Mytable table ([Col 1] varchar(20),[Col 2] varchar(20),[Taken Date] varchar(20),[Date 1] varchar(20),[Date 2] varchar(20),[Date 3] varchar(20))
    Insert into @Mytable ([Col 1],[Col 2],[Taken Date],[Date 1],[Date 2],[Date 3])
    select * from
    Select 'Data' as [Col 1],'Data' as [Col 2],'3/12/2015' as [Taken Date],'3/12/2015 7:22' as [Date 1],'' as [Date 2],'' as [Date 3]
    union all
    Select 'Data' as [Col 1],'Data' as [Col 2],'3/12/2015' as [Taken Date],'' as [Date 1],'3/12/2015 8:47' as [Date 2],'' as [Date 3]
    union all
    Select 'Data' as [Col 1],'Data' as [Col 2],'3/12/2015' as [Taken Date],'' as [Date 1],'' as [Date 2],'3/12/2015 9:27' as [Date 3]
    union all
    select 'Data' as [Col 1],'Data' as [Col 2],'3/22/2015' as [Taken Date],'' as [Date 1],'3/22/2015 7:27' as [Date 2],'' as [Date 3]
    union all
    select 'Data' as [Col 1],'Data' as [Col 2],'3/22/2015' as [Taken Date],'' as [Date 1],'' as [Date 2],'' as [Date 3]
    union all
    select 'Data' as [Col 1],'Data' as [Col 2],'4/12/2015' as [Taken Date],'' as [Date 1],'' as [Date 2],'' as [Date 3]
    union all
    select 'Data' as [Col 1],'Data' as [Col 2],'4/12/2015' as [Taken Date],'' as [Date 1],'' as [Date 2],'' as [Date 3]
    union all
    select 'Data' as [Col 1],'Data' as [Col 2],'4/12/2015' as [Taken Date],'' as [Date 1],'' as [Date 2],'' as [Date 3]
    ) as temp;
    with Mytable2(
    [Col 1],
    [Col 2],
    [Taken Date],
    [Date],
    [NameDate]
    as
    SELECT
    [Col 1],
    [Col 2],
    [Taken Date],
    [Date],
    [NameDate]
    FROM
    (SELECT
    [Col 1],
    [Col 2],
    [Taken Date],
    [Date 1],
    [Date 2],
    [Date 3]
    FROM
    @MyTable) as p
    UNPIVOT
    [Date] FOR [NameDate] IN ([Date 1],[Date 2],[Date 3])
    )AS unpvt
    group by
    [Col 1],
    [Col 2],
    [Taken Date],
    [Date],
    [NameDate]
    Select * from Mytable2 t1 where [date]<>''
    end
    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Ricardo Lacerda

  • Return and combine multiple rows in one record

    Hi friends,
    I have these cursors,
    DECLARE
    CURSOR plaintif_cur IS
    SELECT personel_id, sp_sfs_id
    FROM siv_plaintif
    WHERE SP_SFS_ID IN(70, 74, 182)
    ORDER BY personel_id;
    -- defendan cursor all defendan for a dept number
    CURSOR defendan_cur (v_sp_sfs_id siv_plaintif.SP_SFS_ID%TYPE) IS
    SELECT personel_id, sd_sfs_id
    FROM siv_defendan
    WHERE sd_sfs_id = v_sp_sfs_id
    AND SD_SFS_ID IN(70, 74, 182);
    BEGIN
    FOR plaintif_rec IN plaintif_cur LOOP
    dbms_output.put_line('Plaintif in Sivil '||TO_CHAR(plaintif_rec.sp_sfs_id));
    FOR defendan_rec in defendan_cur(plaintif_rec.sp_sfs_id) LOOP
    dbms_output.put_line('...plaintif is '||plaintif_rec.personel_id);
    END LOOP;
    END LOOP;
    END;
    The output generated was
    Output:
    Plaintif in Sivil 182
    ...plaintif is 38
    Plaintif in Sivil 70
    ...plaintif is 1257
    Plaintif in Sivil 74
    ...plaintif is 1277
    Plaintif in Sivil 74
    ...plaintif is 1278
    However, I want the output to be like this, especially for the record where there are many plaintifs in one Sivil file
    Desired Output:
    Plaintif in Sivil 182
    ...plaintif is 38
    Plaintif in Sivil 70
    ...plaintif is 1257
    Plaintif in Sivil 74
    ...plaintif is 1277, 1278
    I would like to thank those everyone helping.. Thank you.

    Instead of declaring two cursors and doing it in slowest possible manner, possibly you can combine it into one SQL. Search for string aggregation to get some queries in this regard.
    For more specific answer, please post your table structure (CREATE TABLE) and sample data (INSERT statement) with sample output desired. Format your code with tag.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • SQL to combine multiple rows

    Hi All -
    I have following 2 tables (definition and data insertion scripts below).
    COMP table has company related information and
    COMP_CATEGORY table has company category details.
    COMP- table
    COMP_ID | COMP_DESC | COMP_CITY | COMP_STATE
    1111|Sahara Ltd|Columbia|SC
    2222|Paragon Inc|Reno|NV
    3333|Skypx Solutions|Miami|FL
    create table COMP
    COMP_ID varchar2(100),
    COMP_DESC varchar2(200),
    COMP_CITY varchar2(50),
    COMP_STATE char(2)
    insert into COMP values ('1111','Sahara Ltd','Columbia','SC');
    insert into COMP values ('2222','Paragon Inc','Reno','NV');
    insert into COMP values ('3333','Skypx Solutions','Miami','FL');
    COMP_CATEGORY- table
    CAT_TYP_CDE | CAT_CDE | COMP_ID
    001|MO|1111
    001|OTHER|1111
    001|SDB|1111
    002|APAO|1111
    001|SDB|2222
    001|WO|2222
    001|MO|3333
    002|HAO|3333
    create table COMP_CATEGORY
    CAT_TYP_CDE varchar2(10),
    CAT_CDE varchar2(10),
    COMP_ID varchar2(100)
    insert into COMP_CATEGORY values ('001','MO','1111');
    insert into COMP_CATEGORY values ('001','OTHER','1111');
    insert into COMP_CATEGORY values ('001','SDB','1111');
    insert into COMP_CATEGORY values ('002','APAO','1111');
    insert into COMP_CATEGORY values ('001','SDB','2222');
    insert into COMP_CATEGORY values ('001','WO','2222');
    insert into COMP_CATEGORY values ('001','MO','3333');
    insert into COMP_CATEGORY values ('002','HAO','3333');
    The output I want from these 2 tables to display as a report is this:
    OUTPUT:
    COMP_ID | COMP_DESC | COMP_CITY | COMP_STATE | STATUS1 | STATUS2
    1111 | Sahara Ltd | Columbia | SC | MO,OTHER,SDB | APAO
    2222 | Paragon Inc | Reno | NV | SDB,WO | -
    3333 | Skypx Solutions | Miami | FL | MO | HAO
    So basically, companies can have 1 or 2 CAT_TYP_CDE in COMP_CATEGORY table i.e. with values '001' or '002'. if the company has CAT_CDE='MO' then it will have one more entry in COMP_CATEGORY table with CAT_TYP_CDE='002'. So as in the output shown above if the company has 'MO' category then it should show the corresponding '002' category value in STATUS2 column. If it doesnt have 'MO' then the STATUS2 column should be blank.
    Please share your expertise.
    Thanks,
    -Seenu

    Thanks for posting sample data.
    You're looking for string aggregation.
    Here are several techniques listed:
    http://www.oracle-base.com/articles/misc/StringAggregationTechniques.php
    So basically, companies can have 1 or 2 CAT_TYP_CDE in COMP_CATEGORY table i.e. with values '001' or '002'. iIf that's a fixed rule, then you can try something like:
    SQL> with cc_agg1 as ( select comp_id
      2                   ,      ltrim(sys_connect_by_path(cat_cde, ','), ',') cat_cde1
      3                   from ( select comp_id
      4                          ,      cat_typ_cde
      5                          ,      cat_cde
      6                          ,      row_number() over ( partition by comp_id, cat_typ_cde order by cat_cde ) rn
      7                          from   comp_category cc
      8                          where  cat_typ_cde = '001'
      9                        )
    10                   where connect_by_isleaf=1
    11                   start with rn=1
    12                   connect by rn = prior rn+1
    13                          and comp_id = prior comp_id
    14                          and cat_typ_cde = prior cat_typ_cde    
    15                 )               
    16  ,    cc_agg2 as ( select comp_id
    17                   ,       cat_cde cat_cde2
    18                   from    comp_category cc
    19                   where  cat_typ_cde = '002'
    20                 )                              
    21  --
    22  select c.comp_id
    23  ,      c.comp_desc
    24  ,      c.comp_city
    25  ,      c.comp_state
    26  ,      cc1.cat_cde1
    27  ,      cc2.cat_cde2
    28  from   comp c
    29  ,      cc_agg1 cc1
    30  ,      cc_agg2 cc2
    31  where  cc1.comp_id = c.comp_id
    32  and    cc2.comp_id(+) = c.comp_id;
    COMP_ID    COMP_DESC       COMP_CITY  COMP_STATE CAT_CDE1        CAT_CDE2
    1111       Sahara Ltd      Columbia   SC         MO,OTHER,SDB    APAO
    2222       Paragon Inc     Reno       NV         SDB,WO
    3333       Skypx Solutions Miami      FL         MO              HAO

Maybe you are looking for

  • I click on a video & it causes safari to stall untill i quit & reopen it

    I have an Intel MacMini 1.66 running 10.4.10 and Safari 2.0.4. If I click on a video (mpeg or other, doesnt seem to matter), Safari wont load another page or download anything until i quit it & reopen Safari. If i download the video it will download

  • Sending Request Mapping errors back to a consumer for a sync scenario

    Hello Experts, I have a sync scenario (JAVA Application <-> PI <-> CRM (service)) where i want to send back any mapping exception that occurs in PI on the request side of the call, back to the consumer. I also want to communicated back to the consume

  • B2B Deployment overrides the Business Action Selection for Inbound

    Hi, Following is the scenario, please let me know what configuration mistake I am doing and give me any possible Fix or Work around. a. Host_TP_AS2_ID_1 & External_TP_1 ---> Agreement_A --> BusinessAction_A --> Document Rev. Protocol_A --> DocumentTy

  • Red slider will not slide

    My wife's phone, which previously was my own, has frozen! Nothing happens and sliders, such as the red slider, do not slide! Nothing appears to be operating. I have called the number and it rings but likewise I cannot answer the phone. When I try to

  • [SOLVED] where is /dev/null ?

    I need to supress "make" output in arch, in debian-based distro I used to make it via "make &> /dev/null" command, but can't find this in arch, where is /dev/null? Last edited by tasty_minerals (2011-06-01 19:48:35)