Transposing column names to row for a multi row table

Hi
I have a table some thing like this that needs to be transposed.
FIELD_POPULATED First_NM**Last_NM**Mi_NM*
A_NULL 0 0 0
A_NOT_NULL 120 120 120
B_NULL 0 0 0
B_NOT_NULL 0 0 0
The above table has to be transposed as
column_name*A_NULL**A_NOT_NULL**B_NULL* B_NOT_NULL
FIRST_NM 0 120 0 0
Last_NM 0 120 0 0
Mi_NM 0 120 0 0
I am working oracle on 11g. Any help is greatly appreciated

Hi,
See this thread:
Re: Help with PIVOT query (or advice on best way to do this)

Similar Messages

  • Sql Transposing Column Name in Row

    i am using Sql Server 2008
    tbl_EmployeeProfile
    EmployeeId EmployeeName LeaveApplicable Active
    1 Sam true true
    2 Rahul false false
    3 Sameer true true
    tbl_MasterLeave
    id LeaveCode Description active
    1 PL Paid Leave true
    2 CL Casual Leave true
    3 SL Sick Leave false
    tble_LeaveAllocation
    EmployeeId Period 1 2 3 .........31
    1 2014 18 4
    3 2014 20 4
    note: tble_Masterleave.id = tble_LeaveAllocation.1( column Name)
    i.e  value of tbl_masterleave id is mape with column name of tble_LeaveAllocation 1,2,.....31
    Expected out put
    EmployeeId EmployeeeName Period PL CL
    1 Sam 2014 18 4
    3 Sameer 2014 20 4
    Note: show only record who is active = true & leaveApplicable = true  .
    why i made this table structure  because non of organization leave type are not fixed, so user can customize leave according their requirment , so i made tbl_ allocation table with 1 to 31 column , so user can allocate leave type max 31.
    please advice me is it right method or any other good alternative solution 
    Thanks Best Regard Naweez

    Please follow basic Netiquette and post the DDL we need to answer this. Follow industry and ANSI/ISO standards in your data. You should follow ISO-11179 rules for naming data elements. You should follow ISO-8601 rules for displaying temporal data. We need
    to know the data types, keys and constraints on the table. Avoid dialect in favor of ANSI/ISO Standard SQL. And you need to read and download the PDF for: 
    https://www.simple-talk.com/books/sql-books/119-sql-code-smells/
    Why are you so special that you do not have to post DDL? I Googled you and got nothing that would grant you privilege. 
    You have the manners of a pig and your code is garbage. Look up tibbling in the “code smells” paper. That is what we call your “tbl-”
     prefix when we laugh at you. 
    Why do you write SQL with assembly language flags? SQL programmers do not! Why did you use the term “master_” on a table name? This term is from tape files and network DB; it has nothing to do with RDBMS!! 
    Why do you think that “active” is an attribute? NO! It is a value of some particular attribute and needs a temporal range. 
    There is no generic “id” in RDBMS! Remember the Law of Identity from your first freshman logic class? Rows are not records, so you got that term wrong. We do not use mappings in RDBMS; we have REFERENCES. 
    CREATE TABLE Personnel
    (emp_id CHAR(10) NOT NULL PRIMARY KEY,
     emp_name VARCHAR(35) NOT NULL);
    CREATE TABLE Leave_Codes
    (leave_code CHAR(2) NOT NULL PRIMARY KEY,
     leave_code_description VARCHAR (20) NOT NULL);
    INSERT INTO Leave_Codes
    VALUES 
    ('PL', 'Paid Leave'),
    ('CL', 'Casual Leave'),
    ('SL', 'Sick Leave);
    I might have done this: 
    CREATE TABLE Employee_Leaves
    (emp_id CHAR(10) NOT NULL
     REFERENCES Personnel(emp_id)
     leave_start_date DATE NOT NULL,
     leave_end_date DATE NOT NULL,
    CHECK(leave_start_date < leave_end_date),
     leave_code CHAR(2) NOT NULL
      REFERENCES Leave_Codes (leave_code),
     PRIMARY KEY (??),
     >> why I made this table structure because our organization leave type are not fixed, so user can customize leave according their requirement, so I made allocation table with 1 to 31 column, so user can allocate leave type max 31. <<
    No, you did this out of ignorance. You do not understand RDBMS or SQL.  YHou do not know any of the basics. 
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • No Column Name Was Specified for Column 1 of 'ShipFromStoreXML'

    I get the error:
    Msg 8155, Level 16, State 2, Line 16
    No column name was specified for column 1 of 'ShipFromStoreXML'.
    My SQL is as follows:
    SELECT * FROM (
     SELECT [StoreInventoryID] AS A
        ,[StoreID]
        ,[ProductID] AS B
        ,[QtyOnHand]
        ,[QtyDefective]
        ,[QtyTradeHold]
        ,[ModifiedDate]
        ,[CreatedDate]
        ,[QtyReservationHold]
        ,[QtyHopsHold]
        ,[QtyTradeHoldDefective]
       FROM [StoreInformation].[dbo].[StoreInventory]
       WHERE StoreID = 8127
       FOR XML PATH('Item'),ROOT('ShipNode'))
       AS ShipFromStoreXML 
    Ryan P. Casey • <a href="http://www.R-P-C-Group.com">www.R-P-C-Group.com</a>

    You just have to give the column an alias
    SELECT * FROM (
    SELECT [StoreInventoryID] AS A
    ,[StoreID]
    ,[ProductID] AS B
    ,[QtyOnHand]
    ,[QtyDefective]
    ,[QtyTradeHold]
    ,[ModifiedDate]
    ,[CreatedDate]
    ,[QtyReservationHold]
    ,[QtyHopsHold]
    ,[QtyTradeHoldDefective]
    FROM [StoreInformation].[dbo].[StoreInventory]
    WHERE StoreID = 8127
    FOR XML PATH('Item'),ROOT('ShipNode')
    AS ShipFromStoreXML(x)
    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Visakh
    My Wiki User Page
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • What is the column name when use select ... from table(my_table)

    I have some code that takes a csv and loads it into a type table. I am now trying to select from this table but am not sure what column name to use in my cursor. (See below I have c2.???).
    FUNCTION in_list_varchar2 (p_in_list IN VARCHAR2) RETURN VARCHAR2_TT is
    l_tab VARCHAR2_TT := VARCHAR2_TT();
    l_text VARCHAR2(32767) := p_in_list || ',';
    l_idx NUMBER;
    BEGIN
    LOOP l_idx := INSTR(l_text, ',');
    EXIT WHEN NVL(l_idx, 0) = 0;
    l_tab.extend;
    l_tab(l_tab.last) := TRIM(SUBSTR(l_text, 1, l_idx - 1));
    l_text := SUBSTR(l_text, l_idx + 1);
    END LOOP;
    RETURN l_tab;
    END in_list_varchar2;
    schema_list := 'SCOTT, TOM, MIKE';
    schema_names := regexp_replace(schema_list, '([^,]+)', '''\1''');
    schema_list_t := DATAPUMP_UTIL.in_list_varchar2(schema_list);
    for c2 in
    select *from table(schema_list_t)   
    loop
    dml_str := 'DROP USER ' || c2.??? || 'CASADE';
    EXECUTE IMMEDIATE dml_str;
    end loop;

    Chris wrote:
    I have some code that takes a csv and loads it into a type table. I am now trying to select from this table but am not sure what column name to use in my cursor. (See below I have c2.???).
    FUNCTION in_list_varchar2 (p_in_list IN VARCHAR2) RETURN VARCHAR2_TT is
    l_tab VARCHAR2_TT := VARCHAR2_TT();
    l_text VARCHAR2(32767) := p_in_list || ',';
    l_idx NUMBER;
    BEGIN
    LOOP l_idx := INSTR(l_text, ',');
    EXIT WHEN NVL(l_idx, 0) = 0;
    l_tab.extend;
    l_tab(l_tab.last) := TRIM(SUBSTR(l_text, 1, l_idx - 1));
    l_text := SUBSTR(l_text, l_idx + 1);
    END LOOP;
    RETURN l_tab;
    END in_list_varchar2;
    schema_list := 'SCOTT, TOM, MIKE';
    schema_names := regexp_replace(schema_list, '([^,]+)', '''\1''');
    schema_list_t := DATAPUMP_UTIL.in_list_varchar2(schema_list);
    for c2 in
    select *from table(schema_list_t)   
    loop
    dml_str := 'DROP USER ' || c2.??? || 'CASADE';
    EXECUTE IMMEDIATE dml_str;
    end loop;
    I have some code that takes a csv and loads it into a type table.Why a type table? Where is type table defined as such?
    with PL/SQL, objects must be declared before they can be referenced.
    You need to correct syntax errors before tackling any runtime/logic flaws.

  • How can I insert an aggregated column name as a string in the target table?

    I have a large source table, with almost 70 million records.  I need to pull the sum of four of the columns into another target table, but instead of having the same four target columns I just want to have two.
    So, let's take SUM(col1), SUM(col2), SUM(col3), and SUM(col4) from the source DB & insert them into the target like this:
    SOURCE_COLUMN
    | AMOUNT
    1 col1
    | SUM_AMOUNT
    2 col2
    | SUM_AMOUNT
    3 col3
    | SUM_AMOUNT
    4 col4
    | SUM_AMOUNT
    I know how to do this in four separate Data Flows using the source, an Aggregation Transformation, a Derived Column (to hard code the SOURCE_COLUMN label), and destination... but with this many records, it takes over 3 hours to run because it has to loop
    through these records four separate times instead of once.  Isn't there a way to do this with one Data Flow?  I'm thinking maybe Conditional Split?
    Any help is appreciated, thanks!

    Hi ,
      This could be achieved using UNPIVOT transformation. The below sample uses the below source query
    SELECT 1 AS COL1,2 AS COL2,3 AS COL3,4 AS COL4
    setup the UNPIVOT transformation as below
    The output of unpivot transformation will be as below
    Hope this helps.
    Best Regards Sorna

  • How to dynamically set column name in Answers

    Hi.
    How to dynamically set column name in Answers, for example I want to put presentation variable in column header. Is this possible?
    Regards,
    Goran Ocko
    http://108obiee.blogspot.com/

    May be a rude way .. but it works.
    Add narrative view and use Java script to change the column headings based on the variables.
    <script language="javascript" type="text/javascript">
    var a = document.getElementById('idResultsTableParent');
    var rows= a.getElementsByTagName('tr');
    rows[1].cells[1].innerText ="@{Presentation Variable}";
    </script>
    Editing the same post to remove irrelevant information.
    - Girish

  • Alv grid column name display

    alv grid column name could not be displayed fully.we manually want to drag the column,to see the column name fully.  for ex. if column name is 'COMPANYNAME'.it shows 'COMPA' alone.
    how could i solve this problem....?

    hI,
        Check the below code...
    *& Report  ZALV_PROGRAAM
    REPORT  ZALV_PROGRAAM.
    TYPE-POOLS SLIS.
    DATA : BEGIN OF WA_KNA1,
    KUNNR TYPE KUNNR,
    NAME1 TYPE NAME1,
    END OF WA_KNA1,
    IT_KNA1 LIKE TABLE OF WA_KNA1.
    DATA : IT_FCAT TYPE SLIS_T_FIELDCAT_ALV,
    WA_FCAT LIKE LINE OF IT_FCAT.
    SELECT KUNNR NAME1 INTO TABLE IT_KNA1 FROM KNA1 UP TO 5 ROWS.
    PERFORM FCAT USING '1' 'KUNNR' 'CUSTOMERNUMBER' '40'.
    PERFORM FCAT USING '2' 'NAME1' 'CUSTOMERNAME' '40'.
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      I_INTERFACE_CHECK                 = ' '
      I_BYPASSING_BUFFER                = ' '
      I_BUFFER_ACTIVE                   = ' '
       I_CALLBACK_PROGRAM                = SY-CPROG
      I_CALLBACK_PF_STATUS_SET          = ' '
      I_CALLBACK_USER_COMMAND           = ' '
      I_CALLBACK_TOP_OF_PAGE            = ' '
      I_CALLBACK_HTML_TOP_OF_PAGE       = ' '
      I_CALLBACK_HTML_END_OF_LIST       = ' '
      I_STRUCTURE_NAME                  =
      I_BACKGROUND_ID                   = ' '
      I_GRID_TITLE                      =
      I_GRID_SETTINGS                   =
      IS_LAYOUT                         =
       IT_FIELDCAT                       = IT_FCAT
      IT_EXCLUDING                      =
      IT_SPECIAL_GROUPS                 =
      IT_SORT                           =
      IT_FILTER                         =
      IS_SEL_HIDE                       =
      I_DEFAULT                         = 'X'
      I_SAVE                            = ' '
      IS_VARIANT                        =
      IT_EVENTS                         =
      IT_EVENT_EXIT                     =
      IS_PRINT                          =
      IS_REPREP_ID                      =
      I_SCREEN_START_COLUMN             = 0
      I_SCREEN_START_LINE               = 0
      I_SCREEN_END_COLUMN               = 0
      I_SCREEN_END_LINE                 = 0
      I_HTML_HEIGHT_TOP                 = 0
      I_HTML_HEIGHT_END                 = 0
      IT_ALV_GRAPHICS                   =
      IT_HYPERLINK                      =
      IT_ADD_FIELDCAT                   =
      IT_EXCEPT_QINFO                   =
      IR_SALV_FULLSCREEN_ADAPTER        =
    IMPORTING
      E_EXIT_CAUSED_BY_CALLER           =
      ES_EXIT_CAUSED_BY_USER            =
      TABLES
        t_outtab                          = IT_KNA1
    EXCEPTIONS
       PROGRAM_ERROR                     = 1
       OTHERS                            = 2
    IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
             WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    *&      Form  FCAT
          text
         -->P_0052   text
         -->P_0053   text
         -->P_0054   text
         -->P_0055   text
    form FCAT  using    FP_COL_POS
                        FP_FIELDNAME
                        FP_SELTEXT_M
                        FP_OUTPUTLEN.
    WA_FCAT-COL_POS = FP_COL_POS.
    WA_FCAT-FIELDNAME = FP_FIELDNAME.
    WA_FCAT-SELTEXT_M = FP_SELTEXT_M.
    WA_FCAT-OUTPUTLEN = FP_OUTPUTLEN.
    APPEND WA_FCAT TO IT_FCAT.
    CLEAR WA_FCAT.
    endform.                    " FCAT
    thanks,
    Thiru. R

  • Reading MS Project column names and data on the fly from a selected View

    Hi guys,
    I have several views on my project file (MSPROJECT 2010) and I want to build a macro so that;
    1. User can select any view ( Views can have diffrent columns and the user may add new columns as well)
    2. User runs the Macro and all the coulmns along with the tasks displayed in the view will be written to a excel file. ( I don't want to build several macro's for each view, I'm thinking of a common method which would work for any selected view)
    The problem I'm facing is that how will i read the column names and data for a particular view on the fly without hard coding them inside the vba code ?
    The solution needs to work on a master schedule as well.
    Appreciate your feedback.

    Just to get you started the following code writes the field name and data for the active task to the Immediate window.
    Sub CopyData()
    Dim fld As TableField
    For Each fld In ActiveProject.TaskTables(ActiveProject.CurrentTable).TableFields
    If fld.Field >= 0 Then
    Debug.Print Application.FieldConstantToFieldName(fld.Field), ActiveCell.Task.GetField(fld.Field)
    End If
    Next fld
    End Sub
    Rod Gill
    Author of the one and only Project VBA Book
    www.project-systems.co.nz

  • Column name in a query contains special characters

    Hi folks,
    The column name in a query contains special characters. For example ~ or ^. The creator of the table put these column names under double quotation while creating the table. When I get the column names form the result set meta data object it returns without quotation. Is there any way to tell the jdbc driver so that it return those column names as it was created, I mean in double quotation.
    The help is urgent. I will appreciate any suggestions. Thanks �.
    [using oracle driver for 10g]
    Thanks
    Angelina

    Just because the column names were in quotations when the database was created doesn't mean that the quotes are actually part of the names. What's inside the quotes is what makes the column name in the database. If I created a column as "abcd" and put it in quotes just like that ("abcd"), it would go in the database as abcd since SQL would strip off the quotes.
    And there's your answer. Just put all column names in quotes whenever you need to talk to SQL. It will strip off the quotes and understand.
    I think SQL will also accept square brackets ([ and ]).

  • Changing the Column names / alias

    Hi,
    I have an oracle query and it works fine.
    select q.sname,
    SUM( decode(p.nprofile1,10,1,0)) as "0 - 5",
    SUM( decode(p.nprofile1,9,1,0)) as "6 - 10",
    SUM( decode(p.nprofile1,8,1,0)) as "11 - 15",
    SUM( decode(p.nprofile1,7,1,0)) as "16 - 19",
    SUM( decode(p.nprofile1,6,1,0)) as "20 - 20",
    SUM( decode(p.nprofile1,5,1,0)) as "21 - 27",
    SUM( decode(p.nprofile1,4,1,0)) as "28 - 30",
    SUM( decode(p.nprofile1,3,1,0)) as "31 - 40",
    SUM( decode(p.nprofile1,2,1,0)) as "41 - 45",
    SUM( decode(p.nprofile1,1,1,0)) "46 - Over",
    COUNT(q.sname) "TOTAL"
    from task_core@cds t, cor_queue q, profile_core@crb p
    where t.nmboxid = q.nmboxid
    and p.ncodaid = t.nobjectid
    and p.ntype=2
    GROUP BY q.sname
    ORDER BY q.sname
    It generates a Cross-tab sort of result and I am using the decode function to generate the result.
    My problem is that right now I am using hardcoded column names or alias for the columns generated by the decode function. eg. "0-5", "6-10" etc.
    I have another table which contains these values ("0-5","6-10"). I would like to know instead of hard coding the column names like
    SUM( decode(p.nprofile1,10,1,0)) as "0 - 5"
    can we retrieve the values from the Other table that contains the values "0-5","6-10" etc and display it there in the decode function?
    Pls help me with this issue
    Thanks
    Gilles

    hi,
    the column names are always fixed. You can try dynamic sql in pl/sql or spool then execute, but in pure sql, it is not possible

  • Not showing the column name

    Hi
    I am using jdev 11.1.1.3
    .i i dragged an adf table from data control.it has got 3 columns.i changed the name of first column as Lang grades.when i run that it is showing the column name as lang grades.then in that table two fields r mandatory.so in the property inspector i put the show required as true.but after that on running it is not showing the column name as lang grades.there is only the star sign for showing the attribute as required only.

    Hi,
    not enough information. So from your description, a column that is not marked required on its cell renderer component is not displayed at runtime. I am not aware of such a problem and suggest to try a later version of 11g R1 (11.1.1.6) to see if this reproduces. This allows you to exclude a probelm with 11.1.1.3 only
    Frank

  • How to make the display of custom column names in UWL(not bother abt values

    Hi all
    i want to make the display of custom column names in UWL ( for example GP)
    i dont want or not looking about values for those custom columns . i know that thru custom connector we can achieve to retrieve the values for those custom columns. but currently i am looking only just to display the custom column names( for example GP custom column names, just i want to display the name of the columns ) in UWL .
    Thanks
    Sunil

    Hello Prashant,
    You can add the control to your custom pagelayout, the following article has an example:
    http://spandps.com/2012/02/22/showing-the-audience-target-field-in-an-editmodepanel-sharepoint-sp2010-in-projectserver-ps2010/
    Btw, the SPFieldTargetToControl has a required property:
    http://msdn.microsoft.com/en-us/library/microsoft.office.server.webcontrols.fieldtypes.spfieldtargettocontrol.required(v=office.14).aspx
    - Dennis | Netherlands | Blog |
    Twitter

  • Date as column names in a table

    SELECT days all_fridays
       FROM (
             SELECT TO_DATE('0101', 'DDMM') + LEVEL - 1 days
                FROM dual CONNECT BY LEVEL <= TO_NUMBER(TO_CHAR(TO_DATE('3112', 'DDMM'), 'DDD'))
       WHERE to_char(days, 'DY') = 'FRI'Using the above query I'm getting the date's of all 'FRIDAY' day for the current year.
    Please help me with a query or pl/sql block that can create a table (t) with these dates as column names.
    Also, Can we create a table with dates as column names?
    Thank You

    We are all more than welcome to help if you can post your information here. Please don't forget to identify your Oracle version (ex: 10.2.0.4) and post things like the sample data and layout using \ tags (See FAQ for more information on use of tags).
    Thanks!                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Display column name in sql*plus

    Hi,
    How to display full column name?
    there are n no of tables, i have to query the tables but i want the column name to be displayed fully. for example
    SQL> desc control
    Name Null? Type
    CODE NOT NULL VARCHAR2(255)
    LOAD_PERIOD_START_DATETIME DATE
    SQL> select code,load_period_start_datetime from control;
    CODE
    LOAD_PERIOD
    AAA
    01-AUG-2007
    SQL> col load_period_start_datetime format a30
    SQL> /
    CODE
    LOAD_PERIOD_START_DATETIME
    AAA
    01-AUG-2007
    SQL>
    As it is only one column i can set with 'col <column_name> format a 30'
    if there are n no of coumns from n no tables then how do i get the full column name?
    Please help me.
    Thanks

    Hi,
    you can get all the column's for a TABLE from all_tab_columns this VIEW, why dont you write as script which will generate the commands.
    Could you please tell us why do you want to display the compete COLUMN NAME in SQL plus.
    Thanks

  • Lookup column names with Power Query

    Hi,
    before I go ahead and change source files, I was wondering if I can use Power Query to get a model with the following data. To simplify the example, I have the following dataset in an Excel sheet:
    In another Excel sheet, the column names are defined, for example:
    What would like to have in Power Query is one table with the column names from the second screenshot in column B. Is there a way to link these two tables together in Power Query in order to use these names as column headers in the dataset?
    Thanks!
    - If a post answers your question, please click "Mark As Answer" on that post!

    You can filter the list of renames against the list of actual column names with something like
        FilteredColumns = Table.SelectRows(Columns, each List.Contains(Table.ColumnNames(Source), [Name])),
    Again, the working end-to-end:
    let
    Source = Table.FromRows({{"New York", 23, 51, 732}, {"Chicago", 25, 421, 23}, {"Los Angeles", 632, 22, 423}}, {"City", "Col 1", "Col 2", "Col 3"}),
    Columns = Table.FromRows({{"Col 1", "Column 1"}, {"Col 2", "Column 2"}, {"Col 3", "Column 3"}, {"Col 4", "Column 4"}}, {"Name", "Value"}),
    FilteredColumns = Table.SelectRows(Columns, each List.Contains(Table.ColumnNames(Source), [Name])),
    ColumnsAsRenames = Table.TransformRows(FilteredColumns, Record.FieldValues),
    RenamedColumns = Table.RenameColumns(Source, ColumnsAsRenames)
    in
    RenamedColumns

Maybe you are looking for

  • Invoice split due to mismatch in Foreign trade data

    Hi all, While creating a Commercial invoice for Exports with ref to Around 20 Deliveries , the Invoice is getting Split into Two parts, First one consisting of details from 19 deliveries and second consisting of 1 delivery. On analysing the Split Ana

  • HT1349 i have forgotten my password. how can i retrieve it or reset it?

    have forgotten password. hint is old and doesn't work. can't retrieve serial number either. any ideas?

  • GarageBand '11 (6.0.5) How to reinstall MagicGB & Apple Loop Package?

    Alright, Up until the newest update to OSX Mavericks (10.9) I was able to use Magic Garageband & Apple Loops Library with the free added content that it prompted me the first time I used it, which was about 1.5 gigs of content it downloaded directly

  • Where are contacts saved?

    Hi there, This started off as a loss of all contacts from the address book, which has now turned into a curiosity of where exactly do the contacts get saved? I have removed the folder ~/Library/Applications Support/Address Book/ I have actually delet

  • Special GL view

    Hi Friends, When I go to a special GL account ,I need to view the vendor names listed against each line item. Is this possible. Please help. regards, Rajesh