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>

Similar Messages

  • To Combine Multiple STOu2019s into Single Delivery

    Hi,
    What are the configuration settings to be done to combine multiple STOu2019s into one single delivery in VL10B. 
    My requirement is to combine multiple STOu2019s contains different DELIVERY DATES and having SAME SUPPLYING AND RECEIVING PLANT into one single delivery.
    Thanks & Regards,
    Victor.

    Hi
    Delivery in STO is created for single order and for same delivery date, same delivery no. for different delivery date and  for multiple STO is not possible and its not logically correct,since after creation of delivery you will be doing picking and packing and Goods Issue.
    Please check
    Kishor

  • Combining multiple spreadsheets into one workbook with excel

    Im working on a project that requires a workbook with all the raw and calculated data merged into one excel workbook. Currently I have all the sheets saved separately but for the life of me can't figure anything out from the examples i've seen so far. How would I Initially go about doing this?

    Why save the spreadsheets separately?  Can you combine them from the gitgo using the Report Generation toolkit.  How are you collecting the data?  Is the data entry done manually or is it automated?  From your post, it seems you collect the data by some other means other than with LV, but you want to merge the data with LV, correct?
    Take a look at the example finder if you haven't done so.
    Reese, (former CLAD, future CLD)
    Some people call me the Space Cowboy!
    Some call me the gangster of love.
    Some people call me MoReese!
    ...I'm right here baby, right here, right here, right here at home

  • 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.

  • Select or deselect multiple rows with one single selection  event

    Does anyone know how to create a JTable which can select or deselect multiple rows with one single selection event in JTable. Fore example, if the table has
    row1
    row2
    row3
    row4
    row5
    row6
    What I need is when user select row1 or row2, both row1 and row2 should be set to be selected. Then if user press CTRL and click one of row3 or row4, both of them should be selected including the previouse selected row1 and row2.
    For deselection, if row1 and row2 are selected, when users deselect one of row1 or row2, both of them should be deselected.
    Hopefully someone can give me a hint.

    Here is a partial solution using a JList. Only one line gets highlighted when the user makes a selection in the list. But, two lines are returned. There is a blank line between every two lines.
         private void addLineToList() {
              String a = f_one.getText();
              String b = f_two.getText();
              if (a.length() == 0) {
                   Utils.showInformationMessage("Item field is empty.");
                   f_one.requestFocusInWindow();
                   return;
              if (b.length() == 0) {
                   Utils.showInformationMessage("Match field is empty.");
                   f_two.requestFocusInWindow();
                   return;
              model.addElement("item: " + a);
              model.addElement("match: " + b);
              model.addElement(" ");
              int size = model.getSize();
              pairList.setSelectedIndex(size - 3);
              f_one.setText("");
              f_two.setText("");
              f_one.requestFocusInWindow();
         private void editList() {
              if (pairList.getSelectedValue().toString().equalsIgnoreCase(" ")) {
                   Toolkit.getDefaultToolkit().beep();
                   f_one.requestFocusInWindow();
                   return;
              if (!f_one.getText().equals("")) {
                   int result = JOptionPane.showConfirmDialog(this,
                   "The Item field contains text. Replace the text?",
                   "Flash Card Activity", JOptionPane.YES_NO_OPTION,
                   OptionPane.INFORMATION_MESSAGE);
                   if (result == JOptionPane.NO_OPTION) return;
              if (!f_two.getText().equals("")) {
                   int result = JOptionPane.showConfirmDialog(this,
                   "The Match field contains text. Replace the text?",
                   "Flash Card Activity", JOptionPane.YES_NO_OPTION,
                   JOptionPane.INFORMATION_MESSAGE);
                   if (result == JOptionPane.NO_OPTION) return;
              String item = "";
              String match = "";
              int index = pairList.getSelectedIndex();
              String choice = model.getElementAt(index).toString();
              if (choice.startsWith("item")) {
                   item = choice;
                   match = model.getElementAt(index + 1).toString();
                   model.remove(index);
                   model.remove(index);
                   model.remove(index);
              else {
                   item = model.getElementAt(index - 1).toString();
                   match = choice;
                   model.remove(index + 1);
                   model.remove(index);
                   model.remove(index - 1);
              int size = model.getSize();
              if (size > 2) {
                   pairList.setSelectedIndex(size - 2);
              f_one.setText(item.substring(6));
              f_two.setText(match.substring(7));
              f_one.requestFocusInWindow();
         }

  • Hiding filenames when combining multiple files into a single .pdf

    I'm fairly new to this Acrobat X. I'm trying to assemble my portfolio to distribute to employers but I cannot seem to get rid/hide the filenames in the final pdf file. I was using the option to 'combine multiple files into a single pdf' because I was compiling images and documents to a single readable pdf file. I got all that done but once I open it, I'd see that each page would still contain the original file names rather than page numbers - which I prefer not to have employers see for the sake of tidiness (and I refuse to use the Adobe portfolio because it's not really efficient on space or design. I prefer a simple page-by-page pdf). So I was wondering if anyone can tell me how to hide my file names, change them into page numbers or getting rid of them all together so the 'Table of Contents' in the pdf preview mode would not show anything, I would really much appreciate it.
    -Ss

    Well, when the .pdf is in the final, deliverable form; I open it in Mac preview mode and the sidebar is always extended showing a 'table of contents' rather than having each document in the pdf file have a number designating a page name, it shows each individual filename the pdf is composed of. Not too sure about bookmark, though. Thanks for the reply!
    If you want, I can send the file to you.

  • Combining multiple lists into a single list

    Hi, 
    I have created 5 different lists within the same sharepoint site. These lists have some common fields among them for example each list has same fields such as "Country", "Unit", "Review Name" etc. I now want to create a single
    list that will have show only the common fields present in each list. Could you please advise if this can be done and if so how?
    Thanks, Aarti

    To have a full fledged synchronization between 5 lists will be very complicated.
    If the 6th list is a read-only / view only, I would recommend you to create Lists 1, 2,3,4 and 5 as a custom content type.
    Then you can put a Content Query Web Part that filters out your custom content type and combines the content from the three lists.
    or create a  workflow to update the data when new item is added in other lists
    Check the similar post
    http://social.msdn.microsoft.com/Forums/sharepoint/en-US/2480cdbe-acb4-434f-9866-cf716cad0994/combining-multiple-lists-into-a-single-list?forum=sharepointadminlegacy
    http://social.msdn.microsoft.com/Forums/sharepoint/en-US/5a853466-7480-438a-b32d-3ad6d34347ef/combine-lists?forum=sharepointdevelopment

  • Error inserting a row into a table with identity column using cfgrid on change

    I got an error on trying to insert a row into a table with identity column using cfgrid on change see below
    also i would like to use cfstoreproc instead of cfquery but which argument i need to pass and how to use it usually i use stored procedure
    update table (xxx,xxx,xxx)
    values (uu,uuu,uu)
         My component
    <!--- Edit a Media Type  --->
        <cffunction name="cfn_MediaType_Update" access="remote">
            <cfargument name="gridaction" type="string" required="yes">
            <cfargument name="gridrow" type="struct" required="yes">
            <cfargument name="gridchanged" type="struct" required="yes">
            <!--- Local variables --->
            <cfset var colname="">
            <cfset var value="">
            <!--- Process gridaction --->
            <cfswitch expression="#ARGUMENTS.gridaction#">
                <!--- Process updates --->
                <cfcase value="U">
                    <!--- Get column name and value --->
                    <cfset colname=StructKeyList(ARGUMENTS.gridchanged)>
                    <cfset value=ARGUMENTS.gridchanged[colname]>
                    <!--- Perform actual update --->
                    <cfquery datasource="#application.dsn#">
                    UPDATE SP.MediaType
                    SET #colname# = '#value#'
                    WHERE MediaTypeID = #ARGUMENTS.gridrow.MediaTypeID#
                    </cfquery>
                </cfcase>
                <!--- Process deletes --->
                <cfcase value="D">
                    <!--- Perform actual delete --->
                    <cfquery datasource="#application.dsn#">
                    update SP.MediaType
                    set Deleted=1
                    WHERE MediaTypeID = #ARGUMENTS.gridrow.MediaTypeID#
                    </cfquery>
                </cfcase>
                <cfcase value="I">
                    <!--- Get column name and value --->
                    <cfset colname=StructKeyList(ARGUMENTS.gridchanged)>
                    <cfset value=ARGUMENTS.gridchanged[colname]>
                    <!--- Perform actual update --->
                   <cfquery datasource="#application.dsn#">
                    insert into  SP.MediaType (#colname#)
                    Values ('#value#')              
                    </cfquery>
                </cfcase>
            </cfswitch>
        </cffunction>
    my table
    mediatype:
    mediatypeid primary key,identity
    mediatypename
    my code is
    <cfform method="post" name="GridExampleForm">
            <cfgrid format="html" name="grid_Tables2" pagesize="3"  selectmode="edit" width="800px" 
            delete="yes"
            insert="yes"
                  bind="cfc:sp3.testing.MediaType.cfn_MediaType_All
                                                                ({cfgridpage},{cfgridpagesize},{cfgridsortcolumn},{cfgridsortdirection})"
                  onchange="cfc:sp3.testing.MediaType.cfn_MediaType_Update({cfgridaction},
                                                {cfgridrow},
                                                {cfgridchanged})">
                <cfgridcolumn name="MediaTypeID" header="ID"  display="no"/>
                <cfgridcolumn name="MediaTypeName" header="Media Type" />
            </cfgrid>
    </cfform>
    on insert I get the following error message ajax logging error message
    http: Error invoking xxxxxxx/MediaType.cfc : Element '' is undefined in a CFML structure referenced as part of an expression.
    {"gridaction":"I","gridrow":{"MEDIATYPEID":"","MEDIATYPENAME":"uuuuuu","CFGRIDROWINDEX":4} ,"gridchanged":{}}
    Thanks

    Is this with the Travel database or another database?
    If it's another database then make sure your columns
    allow nulls. To check this in the Server Navigator, expand
    your DataSource down to the column.
    Select the column and view the Is Nullable property
    in the Property Sheet
    If still no luck, check out a tutorial, like Performing Inserts, ...
    http://developers.sun.com/prodtech/javatools/jscreator/learning/tutorials/index.jsp
    John

  • Web dynpro screen with multiple rows with columns that can be edited

    Web dynpro screen with multiple rows with columns that can be edited individually:
    Hi
    I am busy creating a screen in web dynpro for ABAP which we would like to make available via Portal ESS (Portal 7).
    I need to add 'n type of table (or almost something like Excel) or something in which someone can type a few paycode numbers (there should be lets say 10 blank rows in which info can be typed in and if I click on a button or so, more rows must be added if necessary.  Then in the other colums stuff like amounts must be entered which one should also be able to edit then and there.
    Can anyone assist in what I can use for this?  There does not seem to be some existing element that I can use.
    Help will be appreciated.
    Regards
    Debbie

    Hi Debbie,
    Whiel Creating table you need to be care full that use chose INPUT FIELD as the CELL EDITOR. Just guessing that if ur table is not editable u might have choosen TextView as default cell editor type.
    check link for details on TABLE UI
    [http://help.sap.com/saphelp_erp2005/helpdata/EN/b5/ac884118aa1709e10000000a155106/frameset.htm]
    easy way is to first add UI ELEMENT TABLE to your VIEW, then right click over it & select create binding from context. After you have a pop up where you can select what columns you want what should be its cell editor etc.
    Greetings
    Prashant

  • Can we create JTable with multiple rows with varying number of columns ?

    Hi All,
    I came across a very typical problem related to JTable. My requirement is that cells should be added dynamically to the JTable. I create a JTable with initial size of 1,7 (row, columns) size. Once the 7 columns are filled with data, a new row should be created. But the requirement is, the new row i.e. second row should have only one cell in it initially. The number of cells should increase dynamically as the data is entered. The table is automatically taking the size of its previous row when new row is added. I tried by using setColumnCount() to change the number of columns to '1' for the second row but the same is getting applied to the first row also.
    So can you please help me out in this regard ? Is it possible to create a JTable of uneven size i.e. multiple rows with varying number of columns in each row ?
    Thanks in Advance.

    Well a JTable is always going to paint the same number of columns for each row. Anything is possible if you want to rewrite the JTable UI to do this, but I wouldn't recommend it. (I certainly don't know how to do it).
    A simpler solution might be to override the isCellEditable(...) method of JTable and prevent editing of column 2 until data in column 1 has been entered etc., etc. You may also want to provide a custom renderer that renderers the empty column differently, maybe with a grey color instead of a white color.

  • When combine multiple PDFs into one, some letters are missing and display wrong letter

    Hi all. I get a problem with combine multiple PDFs into a single PDF document. There are some PDF documents and they are working fine to open each document separately. But after I use Adobe Acrobat 8 Standard to combine them into one, some letters are missing and some display wrong letter (e.g. "forums" display "fo ums"). Our company has Adobe Acrobat 8 Standard, Adobe Acrobat 7 Professional and Standard. But all of them have some problem. Does anyone have idea for that? Please help me! Thanks very much!

    I have a similar situation, but my PDFs look fine in Acrobat Pro 8,Acrobat Reader 8, and Apple preview, but are missing letters in Acrobat Pro 7. I think it stems from the files being combined all having the same font, but each having a unique subset stored in the respective files, but with the same name (and ID?), and when they are combined, the character sets are getting hosed somehow.

  • Combining separated text into single object ...

    I remember in older versions of Illustrator that when you used pathfinder to combine multiple objects into a single object ... it actually made them into a single object, regardless of weather or not they where intersecting.
    With the more recent versions of illustrator, when you try to "unite" objects in pathfinder ... the only ones that are truly combined into a single object are the ones that overlap ... anything separated will simply be "grouped" and remains a totally separate object ... even if you use "expand objects" on the group.
    I'm trying to use a third party program (path styler) and the problem I'm running into is that when I apply a stroke effect in path styler, it treats every letter in my headline as a separate object (even when united in pathfinder), causing the strokes to overlap the previous letter.
    What I want to do is combine all the letters into one single object (while still leaving space between each letter) so that path styler treats the text (and the outlines) properly. (So the outlines run into each other, instead of overlapping the fill.)
    Any help would be appreciated ... this should be simple ... but I think it may be a case of the program trying to preserve the history of "united" objects when I don't want it to.
    Thanks!

    Make your logo ONE entire compound path, you probably have each letter as an individual compound path.

  • Combine multiple drawings into ONE SHEET

    Hello, this is a question on Acrobat Pro, ver 8, using Windows XP. I guess I understand how to combine multiple files into a single PDF-file. However, this morning I happened to see the option mentioned in the subject line. When you go to "Combine files" > "Getting started with combined files" and select "CAD drawings" the description reads: "Combine multiple drawings into one sheet that's easy to navigate and print". How can this be done? I need to combine 8 ea CAD drawings (already converted to PDF) into ONE SHEET for printing without having the need taping 8 pieces of paper together. Arranging the drawing within the CAD application is not an option because the files were delivered by a 3rd party company and they only deliver PDFs

    Hi Priya,
      You can do this by merging the requets.
       1. goto Se10 and right click on the request and seelct merge requests.
       2. It will ask you from request and to request. Give the request names.
       3. After merging first request contents will be added to second request and
           first request will be deleted.
      Like that you can merge 3 requests to one request.
      Let me know if you want more info.  
    Thanks & Regards,
    Siri.

  • Scanning multiple pages into single document

    Is there a way to scan multiple pages into single document?  I am using the following: HP pavilion laptop with windows 8,  HP photosmart C6380 all in one printer scanner copier.

    Hi,
    Please try
    Double click printer icon on desktop,
    Select Scan a Document or Photo,
    Put the first page on the glass (face down),
    Check options (size, dpi ...), and select Scan document to file,
    Click Scan - machine will scan the first page
    Remove the first page on the glass, put the second page,
    Click + (plus sign) It sits on the left hand side of a red x
    Machine will scan the second page, put 3rd page on the glass and click + again ..... to the end then click Save
    Click Done after Save
    Regards.
    BH
    **Click the KUDOS thumb up on the left to say 'Thanks'**
    Make it easier for other people to find solutions by marking a Reply 'Accept as Solution' if it solves your problem.

  • I have 105 rows with alternating columns of No. sold

    I have 105 rows with alternating columns of No. Sold and Amount Sold, for six different dates.  I want the two totals columns on the right to sum every other column for the Total No. Sold and the same but one over for Total Amount Sold.  I know how to do this for a single row, as I have done for the last totals row.  How could I do the formula for all rows without entering it for each one, or if that is not possible, maybe I could copy the formula in some way to make it easier?

    rogerfrombellingham wrote:
    ...  I know how to do this for a single row, as I have done for the last totals row.  How could I do the formula for all rows without entering it for each one, or if that is not possible, maybe I could copy the formula in some way to make it easier?
    Yes, Roger, you can easily copy those formulas for all the rest of the 105 rows.
    Select the two totals cells, click on the little circle in the lower right corner of the selection and drag it to the bottom.
    Jerry

Maybe you are looking for

  • After updating my iphone 4 to iOS 6 messages send and receive very slow. How can I fix this?

    After I updated my phone iOS 6, my messages take way longer than normal to send and be recieved. I need to know how to fix this before I go crazy.

  • Dbc file and Jsp error

    Dear all, I am trying to do multinode installtion on AIX 5.3 HACMP . During post installation i am getting this error. Dbc file and Jsp error Updating Server Security Authentication java.sql.SQLException: Io exception: Invalid number format for port

  • Hd to dvd

    I have a 720p 60 avchd movie . I want to make a sd dvd. How do I do this... is there a tutorial somewhere? Thanks

  • FR reports security Issue

    Hi All, we have developed some reports from Planning cubes. We are using V11.1.1.3 We have created a user(tried with both native & LDAP user) and given the following access. This user has provision for 1. Planning APP - Planner 2. BI Plus - Explorer,

  • Running VI's on Labview 7.1 with Windows 7

    Hi, So I know that Labview 7.1 is not support by Windows 7, but I have noticed people on these forums have been getting it to work (sort of). I have managed to get our PCI 6221 card to work on our Windows 7 x86 machine with NI-DAQmx 9.4 installed, an