How to convert data from rows into columns

Hi,
I have a sql table and the data looks like this
GLYEAR GLMN01 GLMN02 GLMN03 GLMN04
2007 -109712.40 6909.15 4758.72 56.88
2007 -13411.32 19132.9 -5585.07 4362.64
Where GLyear reprsents Year and GLMN01 is February, GLMN02 is March and so on,
Now i want my output to be something like this which i want to insert into another table
GLYear GLMonth GLAmount
2007 February -109712.40
2007 March 6909.15
2007 April 56.88
My new table has 3 columns, GLYear,GLMonth,GLAmount.
Can someone please help me with the select statement on how to do this, i can work with the inserts.
Thanks.

I want you to check these form tread they have the same discussion as you.  They will definitely solve your problem
http://blog.jontav.com/post/8344518585/convert-rows-to-columns-columns-to-rows-in-sql-server
http://dba.stackexchange.com/questions/19057/convert-rows-to-columns-using-pivot-in-sql-server-when-columns-are-string-data
http://stackoverflow.com/questions/18612326/how-to-convert-multiple-row-data-into-column-data-in-sql-server
I hope this helps you in solving your problem. 
Please remember to click “Mark as Answer” on the post that has answered your question as it is very relevant to other community members dealing with same problem in seeking the right answer

Similar Messages

  • How can I display the rows into columns.

    How can I display the rows into columns. I mean
    Create table STYLE_M
    (Master varchar2(10), child varchar2(10));
    Insert itno style_m
    ('MASTER1','CHILD1');
    Insert itno style_m
    ('MASTER2','CHILD1');
    Insert itno style_m
    ('MASTER2','CHILD2');
    Insert itno style_m
    ('MASTER3','CHILD1');
    Insert itno style_m
    ('MASTER3','CHILD2');
    Insert itno style_m
    ('MASTER3','CHILD3');
    Note : The Master may have any number of childs.
    I want to display like this..
    Master child1, child2, child3, .......(dynamic)
    MASTER1 CHILD1
    MASTER2 CHILD1 CHILD2
    MASTER3 CHILD1 CHILD2 CHILD3
    Sorry for disturbing you. Please hlp me out if you have any slution.
    Thanks alot.
    Ram Dontineni

    Here's a straight SQL "non-dynamic" approach.
    This would be used if you knew the amount of children.
    SELECT
         master,
         MAX(DECODE(r, 1, child, NULL)) || ' ' || MAX(DECODE(r, 2, child, NULL)) || ' ' || MAX(DECODE(r, 3, child, NULL)) children
    FROM
         SELECT
              master,
              child,
              ROW_NUMBER() OVER(PARTITION BY master ORDER BY child) r
         FROM
              style_m
    GROUP BY
         master
    MASTER     CHILDREN                        
    MASTER1    CHILD1                          
    MASTER2    CHILD1 CHILD2                   
    MASTER3    CHILD1 CHILD2 CHILD3             Since you said that the number of children can vary, I incorporated the same logic into a dynamic query.
    SET AUTOPRINT ON
    VAR x REFCURSOR
    DECLARE
            v_sql           VARCHAR2(1000) := 'SELECT master, ';
            v_group_by      VARCHAR2(200)  := 'FROM (SELECT master, child,  ROW_NUMBER() OVER(PARTITION BY master ORDER BY child) r FROM style_m) GROUP BY master';
            v_count         PLS_INTEGER;
    BEGIN
            SELECT
                    MAX(COUNT(*))
            INTO    v_count
            FROM
                    style_m
            GROUP BY
                    master;
            FOR i IN 1..v_count
            LOOP
                    v_sql := v_sql || 'MAX(DECODE(r, ' || i || ', child, NULL))' || ' || '' '' || ';
            END LOOP;
                    v_sql := RTRIM(v_sql, ' || '' '' ||') ||' children ' || v_group_by;
                    OPEN :x FOR v_sql;
    END;
    PL/SQL procedure successfully completed.
    MASTER     CHILDREN
    MASTER1    CHILD1
    MASTER2    CHILD1 CHILD2
    MASTER3    CHILD1 CHILD2 CHILD3I'll point your other thread to this one.

  • How to convert date from ccyymm format to mmddyy

    hi,
    How to convert date from ccyymm format to mmddyy

    Please don't multipost. This question has been answered in your first post.
    How to convert date to ccyymm format
    Regards,
    Jo

  • How to load data from Quikbooks into PeopleSoft General Ledger module ?

    Folks,
    Hello.
    My client's data is currently stored in Quikbooks.
    After install PeopleSoft FSCM 9.0, I need to load the data from Quickbooks into PeopleSoft General Ledger module. But I don't know how to use PeopleSoft Integration Broker to integrate with Quikbooks.
    Can any folks tell me how to load data from Quikbooks into PeopleSoft General Ledger module ?

    Hi,
    If the data load is one time process, then you can use PL/SQL or datamover to load the data to PeopleSoft application.
    If you want to load the data in real time, then you need to create In-bound and out-bound nodes to perform the transaction.
    Thanks
    Soundappan

  • How to convert date from "yyyymmdd" to "MM/DD/YYYY" format

    1. I have one BLDAT field in my internal table.
       its getting updated from input file.
    2. The value in the input file is like yyyymmdd.
       So the internal table field is filled like this
       "YYYYMMDD".
    3. After this,I have to compare this internal table  
       field with BSAD table.
    4. The BLDAT field in BSAD table is in the format of 
       "MM/DD/YYYY".
    5. the BLDAT field is having diff format in internal  table and BSAD table.So I am unable to check this value.
    How to convert it as like the BSAD table format."MM/DD/YYYY" format.
    Thanks in advance!!

    Using the WRITE statement
      data: gd_date(10).  "field to store output date
    * Converts date from 20020901 to 09.01.2002
      write sy-datum to gd_date mm/dd/yyyy.
    OR u can
    CONCATENATE gd_date+4(2) gd_date+6(2) gd_date+0(4)
    into gd_date seperated by '/' .
    Hope this helps.
    Kindly reward points and close the thread for the
    answer which helped u OR get back with queries.

  • How to save data from form into database

    i nid to save data from form into the new table, @abc.
    got any idea ?
    smtg like oObj = BaseAddOn.Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oPurchaseDeliveryNotes) this but it is a new object or user data source.
    Thanks

    hi
    i have created UDO i have also done registration  i want to bind item master completely to matrix and then in one column i will set check box to check unchecked and then i want to save it to database
    i have one user defined form and 4 matrix and 4 child tables
    for each matrix i have given 1 form and i have to transfer the data from temp form to main form matrix having large data in matrix on temp form to main form matrix
    to load data on matrix i have used for loop that i want to avoid so how i can bind large data to matrix without for loop
    regards
    amey

  • How to populate data from table into datagrid in form

    hi there. may i know how to populate data from a table into a datagrid? i have created a datagrid in a form using OLE's microsoft datagrid. i'm having problem to populate data from table into the grid. can i know how to do that? thanks

    Not exactly. I want to enter input from form and the user can have all options to choose i.e. HIGH, MEDIUM or so on.
    Suppose, you have option to select HIGH, MEDIUM or LOW and you can see all these options together. You select LOW and when you save, it is saves in the table as a value. So when you view the table again, it will show LOW as active and HIGH and MEDIUM are null.

  • How to convert a table data from rows to columns?

    Hi,
    I have a Employee table of the following format:
    Emp_id | Emp_name | Salary
    101 | James | 1000
    102 | Julia     | 2000
    I have to convert or transpose the table data as follows using a SQL statement/function -
    Emp_id | 101     |     102
    Emp_name | James |     Julia
    Salary     | 1000 |     2000
    How do I achieve this?
    Please help me.
    Thanks,
    993012
    Edited by: 993012 on Mar 11, 2013 3:26 AM

    993012 wrote:
    Hi Pavan,
    Thanks for the prompt reply.
    The link seems to be of not relevant to my question.
    My question is to clearly transpose the rows to columns and vice versa without any changes to data.
    Regards,
    993012I do not see any modification to the data in the Link posted by Pavan. Anyways, One catch with Transposing the Rows is, you need to know the Number of Columns you need to project.
    With Static SQL, there is no way to do so. Hence, you will need PL/SQL with Execute Immediate/Dynamic SQL.
    See demostration by Tom Kyte on Dynamic Pivots to have a look at the example and adapt to your situation.
    Although, I will debate on the need to do it in SQL. Because what you are upto is a part of Reporting and there are many reporting Tools which will have this functionality in-built. SQL, ideally should not be used for reporting purposes. It sole purpose it to store and pass the data to be rendered by Client Software i.e. Java or Third Party tools.

  • Transposing Table Data From Rows to Columns Into a View

    I have a web-based HRMS (Human Resources Management System) ERP with a back-end SQL Server 2008 R2. I'm trying to compare the actual manpower with the manpower contract requirements for 30 cost centers. My base data is as follows:
    TABLE Contract_Requirements: Class, Cost_Center, Contract_Qty
    VIEW Manpower_Count: Class, Cost_Center, Head_Count
    I would like to transpose the rows to columns of both objects so that the end result would be similar to the following:
              Class          |          Site_1          |         
    Site_2          |          Site_3          |          Site_4         
    |...
    Superintendent                   1                              
    1                             1                            
    1
    Supervisor                           2                              
    2                             2                            
    2
    Medic                                   1                              
    2                             1                            
    3
    Crane Operator                   1                              
    1                             2                            
    1
    The target layout is that each individual record displays the number of employees of a specific class allocated to each individual cost center; the cost centers become columns. I was able to accomplish this using the following TSQL:
    DECLARE @cols AS NVARCHAR(MAX), @query AS NVARCHAR(MAX)
    SELECT @cols = STUFF((SELECT ',' + QUOTENAME(Cost_Center)
    FROM Manpower_Count
    GROUP BY Cost_Center
    ORDER BY Cost_Center
    FOR XML PATH(''), TYPE
    ).value('.', 'NVARCHAR(MAX)'),1,1,'')
    SET @query = 'SELECT Class,' + @cols + ' INTO
    Manpower_Allocation_Matrix FROM
    (SELECT Class, Cost_Center, Head_Count
    FROM Manpower_Count) x
    PIVOT (SUM(Head_Count) FOR Cost_Center IN (' + @cols + '))p'
    EXECUTE(@query);
    The only problem is if an employee is transferred from one cost center to another, which happens a lot on a daily basis, this would only be reflected in the base view; the resultant table will not be updated. I would have to repeatedly drop and recreate
    the table which isn't efficient, nor is it the right practice. I was thinking of automating this using a scheduled procedure every day, but it's still not going to work. The actual manpower count must be known at real-time, meaning any changes should be reflected
    immediately after any employee transfer. What is the most efficient way to automate this process and store real-time data? FYI, I'm not an SQL expert and have never worked with
    stored procedures or triggers. I would also like to point out the number of cost centers is never fixed; consequently the number of columns aren't fixed either.

    Hi Seif,
    You can pivot straightly on the base view to get real time data. The dynamic PIVOT is encapsuled in a Stored Procedure(SP), so every time your want to check the manpower count you can call the SP.
    --This table is the same with your base view
    CREATE TABLE srcTbl(
    Employee_Code VARCHAR(99),
    Employee_Name VARCHAR(99),
    Cost_Center_name VARCHAR(99),
    Cost_Center_NO VARCHAR(99),
    Position_ VARCHAR(99),
    Total_Salary Money
    INSERT INTO srcTbl VALUES('CAN-010','John Doe A','Site 120',120,'Fork Lift Operator',150);
    INSERT INTO srcTbl VALUES('EGY-130','John Doe B','Site 150',150,'Driver',200);
    INSERT INTO srcTbl VALUES('IND-120','John Doe C','Site 113',113,'Fork Lift Operator',150);
    INSERT INTO srcTbl VALUES('SAU-50','John Doe D','Site 112',112,'Mechanic',261.948);
    INSERT INTO srcTbl VALUES('PHI-90','John Doe F','Site 112',112,'Crane Operator',250);
    INSERT INTO srcTbl VALUES('CAN-012','John Doe G','Site 120',120,'Driver',200);
    INSERT INTO srcTbl VALUES('IND-129','John Doe I','Site 150',150,'Superintendent',2300);
    INSERT INTO srcTbl VALUES('PAK-464','John Doe X','Site 141',141,'Supervisor',1800);
    INSERT INTO srcTbl VALUES('FRA-003','John Doe M','Site 120',120,'Medic',700);
    GO
    CREATE PROC proc1
    AS
    DECLARE @cols AS NVARCHAR(MAX), @query AS NVARCHAR(MAX)
    SELECT @cols = STUFF((SELECT ',' + QUOTENAME(Cost_Center_no)
    FROM srcTbl
    GROUP BY Cost_Center_no
    ORDER BY Cost_Center_no
    FOR XML PATH(''), TYPE).value('.', 'NVARCHAR(MAX)'),1,1,'')
    SET @query=N';WITH Cte AS(
    SELECT Position_ as Class,Cost_Center_No, COUNT(1) AS Head_Count FROM srcTbl
    GROUP BY Position_,Cost_Center_No
    SELECT Class,'+@cols+'
    FROM Cte
    PIVOT
    (MAX(Head_Count) FOR Cost_Center_No IN('+@cols+')) AS PvtTbl
    ORDER BY Class';
    EXEC sp_executesql @query ;
    GO
    EXEC PROC1
    DROP PROC PROC1
    DROP TABLE srcTbl
    If you have any question, feel free to let me know.
    Eric Zhang
    TechNet Community Support

  • How to push data from BW into SAP R/3 system???

    Hello,
    We have faced a problem. We need to push compressed sales data from BW to SAP R/3 system. But We don't know how to do it.
    Does it exist the standard instruments for it (without ABAP development)?
    How to integrate BW and SAP system?
    We will be much obliged you for your recomendations and advices.

    Hi Igor,
    I'm not aware of any standard out of the box mechanisms for moving Sales data back into SAP ERP. There are some delivered "retractors" for business scenarios like financial planning and consolidations where updated data is sent back to SAP ERP in a closed loop scenario. These retractors have been written in ABAP.
    I would suggest that you search the latest BI content to see if there is anything for sales data retraction. There might also be information in SAP note on how to do this in code.
    To send data from BI, you can also use the 'open hub' feature to extract the BI data to a DB table or file for example. This could then be read by a program to load SAP ERP. The loading would have to be custom development.
    Sorry I can't help you more - I fear you will most definitely have some custom development in this case.
    Cheers,
    Mike.

  • How to insert data from file into matlab script node

    I have interfaced input data from file to be processed using matlab script node. But the problem is that I could not capture the multiple data into matlab script node and to convert it into matrix. Further to this I need to process the data by plotting graphs from it. Thank you in advance for the advice

    Zarina,
    To clarify your problem, you have a script node contaning your Matlab code. Are you then using the standard LV functions to load in your data from a file and pass it into the script node?
    Regards
    Tristan

  • How to insert data from site into DB?

    Hi
    Does anyone know how to insert data into a database from a
    website?
    I have created a Registration form for users to register to
    my web site. With this I would like the data they have entered to
    be stored in a MySQL database. I have created the a form and used
    the record insertion form wizard.
    When they have registered, I need to be able to check their
    username every time they log in.
    If anyone could help, it would be greatly appreciated,
    thanks Lou.

    LoobieLouLou wrote:
    > When I inserted a form, I enetered a name and the method
    was POST, but it also needed an action.
    > How do I write in java script that it needs to be
    inserted into the database?
    You can't do it with JavaScript. You need to use a
    server-side language
    like ASP, ASP.NET, ColdFusion, or PHP. Dreamweaver automates
    a lot of
    the process for you, but you need to choose your server model
    first.
    It sounds as though you are completely new to this. First ask
    your
    hosting company whether it supports a server-side language,
    and if so,
    which one. Then open Dreamweaver help (F1) and read the
    section titled
    "Preparing to Build Dynamic Sites".
    Working with server-side languages and databases isn't
    difficult, but
    it's not something you can pick up in five minutes or be
    shown how to do
    in a couple of forum posts.
    If you can't make up your mind which server-side language to
    use,
    ASP.NET is the most difficult of the four I mentioned. ASP is
    popular,
    but is no longer actively developed, so will eventually die
    out
    (although it will take many years to do so). ColdFusion and
    PHP are
    relatively easy to learn. I prefer PHP, but all of them do
    basically the
    same thing. However, you must choose one; they cannot be
    mixed.
    David Powers, Adobe Community Expert
    Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
    Author, "PHP Solutions" (friends of ED)
    http://foundationphp.com/

  • How to Retrieve data from database into another form ?

    Good Day!
    Am currently new at JSP. I've been studying it for awhile and still getting the hang of it. We are working on a project.
    Editing a given data. We have to retrieve the given data and post it to another form "Editing form".
    Since we can retrieve data using JSP but how are we going to post it to another form? I mean how are we going to transfer data from one form to another?
    Can anyone help me with codes please..

    The client is a web browser.
    The client submits a request (click a link, visit a form)
    The server gets to respond to this
    - look at request parameters from the client
    - access database
    - produce resulting html page
    - send page back to client.
    The standard pattern is to retrieve data from the database in java code, and then load that data into a bean.
    You then make that bean available as an attribute
    It is then available for use in your JSP - either <jsp:useBean> tag or using ${ELexpressions}
    All you can pass from the client to the server is request parameters - which are always strings.
    Draw a picture of where the information is, and the information flows. Very rarely does it go directly from one "form" to another.
    Cheers,
    evnafets

  • How to put data from database into array

    I need to answer hot to put data from database directly into array.
    I tried like the code below but the error message said: java.lang.ArrayIndexOutOfBoundsException: 0, and it points to this line: numbers [row][0]= rs.getString("ID");
    Hope you can help.
    ResultSet rs = stmt.executeQuery(query);
         int row=0;
         String [] [] numbers=new String [row][10];
         // output resultset
         while ( rs.next() )
              numbers [row][0]= rs.getString("ID");
              numbers [row][1]= rs.getString("name");
         row++;
         // close resultset
         rs.close();
    thanks,Devi

    The exception is been thrown simply because you assigned '0' to the 'row' variable, indicating a zero length of the array. In fact you should assign the row count to it.
    After all, don't do that. Make use of the Collection framework and map the ResultSet to a Collection of DTO's.
    List<User> users = new ArrayList<User>();
    while (resultSet.next()) {
        User user = new User();
        user.setID(resultSet.getString("ID"));
        user.setName(resultSet.getString("name"));
        users.add(user);
    }

  • Without NI DAQ device- how to get data from MSP into labVIEW and process it

    Hi,
    I do not have an NI DAQ device. I have an MSP430 and my sensor is an ADXL335 Accelerometer. How do I get data from my MSP into labVIEW and process it?
    Just looking for a nudge in the right direction. I'm having a hard time finding resources on labVIEW that don't involve NI specific DAQs. 
    Thanks in advance,
    Aziz

    There are many ways to get data into LabVIEW that do not involve NI-DAQ devices.
    I think your easiest option would be to stream it via serial port if the data rate isn't too fast.
    Troy
    CLDEach snowflake in an avalanche pleads not guilty. - Stanislaw J. Lec
    I haven't failed, I've found 10,000 ways that don't work - Thomas Edison
    Beware of the man who won't be bothered with details. - William Feather
    The greatest of faults is to be conscious of none. - Thomas Carlyle

Maybe you are looking for

  • New office network setup idea, can anyone help!

    Hi all I wish to do the following and would help and advice from this group to guide our purchases and development of the following; I wish to set up a company dedicated LAN [with wifi access]. We also need to access the system via ftp and some way r

  • Error Message: "OBJECTS_OBJREF_NOT_ASSIGNED"

    Hi All,      One of our cube to which we are picking the data from oracle using DBConnect creating a problem. In monitor screen, the request is still running. But in ST22, it throwed a runtime error with the short text "Access not possible using 'NUL

  • Query on FCC File Receiver

    Hi Experts, In our Scenario the receiver is File FTP. While doing FCC, we have use ';' as the default delimiter. Now our requirement is when the default delimiter (semicolon) is present in a field value we need to use '@' as the delimiter. Can you pl

  • TS1702 siri is not working correctly

    siri is not working correctly & i need how to transfer the Microsoft office files example MS-Word file from my laptop to Ipad. how i install alredy purchased apps to my Ipad.

  • Do i need to leave my MacBook at the store after a genius appt.?

    All I need is the bottom panel and trackpad fixed. Do I need to leave my MacBook at the store? I'm afraid they will go thru my stuff or something..