How to convert Rows to different columns

Hi All,
I am having a table address with the following data.
ID          REL_NAME     REL_RELATION  REL_PHONE
1---          kish_rel1---     wife---     1111
1---          kish_rel2---     sister---     2222
1---          kish_rel3---     brother---     3333
2---          ram_rel1---     brother---     4444
Now i want to display rows data into columns. See the output i want. Exactly, I dont know how many rows are there for each ID. It may increase or decrease.
ID          REL_NAME     REL_RELATION  REL_PHONE
1---kish_rel1---     wife---     1111---kish_rel2---     sister---     2222---kish_rel3---     brother---     3333
2---ram_rel1---     brother---     4444
Thanks in advance,
Pal

Hi,
I have found this is useful. But it is static. It wont work if we dont know the maximum number of rows present when grouped by ID.
Is there any other solution, which will give correct values, if we dont know the row count when grouped by ID.
SELECT hrid,
MAX(case when seq=1 then rel_name end) AS "rel_name1",
MAX(case when seq=1 then rel_relation end) AS "rel_relation1",
MAX(case when seq=1 then rel_phone end) AS "rel_phone1",
MAX(case when seq=2 then rel_name end) AS "rel_name2",
MAX(case when seq=2 then rel_relation end) AS "rel_relation2",
MAX(case when seq=2 then rel_phone end) AS "rel_phone2",
MAX(case when seq=3 then rel_name end) AS "rel_name3",
MAX(case when seq=3 then rel_relation end) AS "rel_relation3",
MAX(case when seq=3 then rel_phone end) AS "rel_phone3",
MAX(case when seq=4 then rel_name end) AS "rel_name4",
MAX(case when seq=4 then rel_relation end) AS "rel_relation4",
MAX(case when seq=4 then rel_phone end) AS "rel_phone4"
FROM (SELECT hrid, rel_name, rel_relation, rel_phone, ROW_NUMBER() over(partition by hrid ORDER BY hrid) AS seq FROM address)
GROUP BY hrid
Thanks,
Pal

Similar Messages

  • How to convert row data into columns without using pivot table?

    Hello guys
    I have a report that has several columns about sales call type and call counts
    It looks like this:
    Calls Type Call Counts
    Missed 200
    Handled 3000000
    Rejected 40000
    Dropped 50000
    Now I wanna create a report that look like this:
    Missed call counts Handled Call counts Rejected Counts Drop counts Other Columns
    200 300000000 40000 50000 Data
    So that I can perform other calculations on the difference and comparison of handled calls counts vs other call counts..
    I know pivot table view can make the report look like in such way, but they cant do further calculations on that..
    So I need to create new solid columns that capture call counts based on call types..
    How would I be able to do that on Answers? I don't have access to the RPD, so is it possible to do it sololy on answers? Or should I just ask ETL support on this?
    Any pointers will be deeply appreciated!
    Thank you

    Thanks MMA
    I followed your guidance and I was able to create a few new columns of call missed count, call handled counts and call abandoned counts.. Then I create new columns of ave missed counts, ave handled counts and so forth..
    Then I went to the pivot view, I realized there is a small problem.. Basically the report still includes the column "call types" which has 3 different types of call "miss, abandon and handled". When I exclude this column in my report, the rest of the measures will return wrong values. When I include this column in the report, it shows duplicate values by 3 rows. It looks like this:
    Queue name Call types Call handled Call missed Call abondoned
    A Miss 8 10 15
    A Handled 8 10 15
    A Abandoned 8 10 15
    in pivot table view, if I move call type to column area, the resulted measures will become 8X3, 10X3 and 15X3
    So is there a way to eliminate duplicate rows or let the system know not to mulitply by 3?
    Or is this as far as presentation service can go in terms of this? Or should I advice to provide better data from the back end?
    Please let me know, thanks

  • How to convert rows into single columns in Oracle?

    I have table with data like shown below in Oracle database.
    P_COLUMN
    COLUMN_1
    COLUMN_2
    COLUMN_3
    COLUMN_ 4
    COLUMN_5
    COLUMN_6
    COLUMN_7
    COLUMN_8
    COLUMN_9
    COLUMN_10
    1
    A1
    A2
    A3
    A4
    A5
    A6
    A7
    A8
    A9
    A10
    1
    B1
    B2
    B3
    B4
    B5
    B6
    B7
    B8
    B9
    B10
    1
    C1
    C2
    C3
    C4
    C5
    C6
    C7
    C8
    C9
    C10
    2
    AA1
    AA2
    AA3
    AA4
    AA5
    AA6
    AA7
    AA8
    AA9
    AA10
    2
    BB1
    BB2
    BB3
    BB4
    BB5
    BB6
    BB7
    BB8
    BB9
    BB10
    I need a query to get one row based on P_COLUMN's value i.e. for P_COLUMN =1, below should be output :-
    C_1
    C_2
    C_3
    C_4
    C_5
    C_6
    C_7
    C_8
    C_9
    C_10
    C_11
    C_12
    C_13
    C_14
    C_15
    C_16
    C_17
    C_18
    C_19
    C_20
    C_21
    C_22
    C_23
    C_24
    C_25
    C_26
    C_27
    C_ 28
    C_29
    C_30
    C_31
    1
    A1
    A2
    A3
    A4
    A5
    A6
    A7
    A8
    A9
    A10
    B1
    B2
    B3
    B4
    B5
    B6
    B7
    B8
    B9
    B10
    C1
    C2
    C3
    C4
    C5
    C6
    C7
    C8
    C9
    C10
    2
    AA1
    AA2
    AA3
    AA4
    AA5
    AA6
    AA7
    AA8
    AA9
    AA10
    BB1
    BB2
    BB3
    BB4
    BB5
    BB6
    BB7
    BB8
    BB9
    BB10
    NULL
    NULL
    NULL
    NULL
    NULL
    NULL
    NULL
    NULL
    NULL
    NULL
    i searched google and found PIVOT, CROSS JOIN etc but could not use those keyword properly.
    Thanks in advance.
    Note - My DB client version is 11g.

    Since you have 11G, here's an alternative with the PIVOT clause.
    First, set up test data with up to 10 rows:
    CREATE TABLE T(P1,C1,C2,C3,C4,C5,C6,C7,C8,C9,C10) AS SELECT
    1,1,2,3,4,5,6,7,8,9,10 FROM DUAL;
    INSERT INTO T
    WITH DATA AS (SELECT LEVEL*10 N FROM DUAL CONNECT BY LEVEL <= 9)
    SELECT P1, C1+N, C2+N, C3+N, C4+N, C5+N, C6+N, C7+N, C8+N, C9+N, C10+N
    FROM T, DATA;
    INSERT INTO T
    SELECT P1+1,C1,C2,C3,C4,C5,C6,C7,C8,C9,C10
    FROM T
    WHERE C1 <= 11;
    select * from t order by p1,c1;
    P1
    C1
    C2
    C3
    C4
    C5
    C6
    C7
    C8
    C9
    C10
    1
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    1
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    1
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    1
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    1
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    1
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    1
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    1
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    1
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    1
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    2
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    2
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    Now the SELECT statement using PIVOT:
    SELECT * FROM (
      SELECT T.*,
      ROW_NUMBER() OVER (
        PARTITION BY P1
        ORDER BY C1,C2,C3,C4,C5,C6,C7,C8,C9,C10
      ) RN
      FROM T
    PIVOT(
      MAX(C1) C1, MAX(C2) C2, MAX(C3) C3, MAX(C4) C4, MAX(C5) C5,
      MAX(C6) C6, MAX(C7) C7, MAX(C8) C8, MAX(C9) C9, MAX(C10) C10
      FOR RN IN (1 R1,2 R2,3 R3,4 R4,5 R5,6 R6,7 R7,8 R8,9 R9,10 R10)
    P1
    R1_C1
    R1_C2
    R1_C3
    R1_C4
    R1_C5
    R1_C6
    R1_C7
    R1_C8
    R1_C9
    R1_C10
    R2_C1
    R2_C2
    R2_C3
    R2_C4
    R2_C5
    R2_C6
    R2_C7
    R2_C8
    R2_C9
    R2_C10
    R3_C1
    R3_C2
    R3_C3
    R3_C4
    R3_C5
    R3_C6
    R3_C7
    R3_C8
    R3_C9
    R3_C10
    R4_C1
    R4_C2
    R4_C3
    R4_C4
    R4_C5
    R4_C6
    R4_C7
    R4_C8
    R4_C9
    R4_C10
    R5_C1
    R5_C2
    R5_C3
    R5_C4
    R5_C5
    R5_C6
    R5_C7
    R5_C8
    R5_C9
    R5_C10
    R6_C1
    R6_C2
    R6_C3
    R6_C4
    R6_C5
    R6_C6
    R6_C7
    R6_C8
    R6_C9
    R6_C10
    R7_C1
    R7_C2
    R7_C3
    R7_C4
    R7_C5
    R7_C6
    R7_C7
    R7_C8
    R7_C9
    R7_C10
    R8_C1
    R8_C2
    R8_C3
    R8_C4
    R8_C5
    R8_C6
    R8_C7
    R8_C8
    R8_C9
    R8_C10
    R9_C1
    R9_C2
    R9_C3
    R9_C4
    R9_C5
    R9_C6
    R9_C7
    R9_C8
    R9_C9
    R9_C10
    R10_C1
    R10_C2
    R10_C3
    R10_C4
    R10_C5
    R10_C6
    R10_C7
    R10_C8
    R10_C9
    R10_C10
    1
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    2
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20

  • How to Convert Rows of the Columns in Multiple Columns

    Hi,
    I have Data in one of the table of Oracle Application.
    Sample Data.....
    Period_Start_date Period_Type Demand
    09-22-2005 1 5
    09-21-2005 1 10
    09-20-2005 1 5
    09-19-2005 1 2
    09-18-2005 1 20
    09-17-2005 1 19
    09-16-2005 1 3
    Output Required.
    Period 6 Period 5 Period 4 Period 3 Period 2 Period 1 Current
    3 19 20 2 5 10 5
    This need to be Done in Using SQL Statement.
    On the base of Current Date enter by the User ...it will pickup last six date and Demand on that Date in Required Format.
    Pls Do let me know Any more Clarification
    Pls can any body Help me
    Regards
    Roshan

    CREATE TABLE t1
    ( col1 VARCHAR2(10),
    col2 VARCHAR2(100)
    INSERT INTO t1 VALUES('A','123,456,789');
    INSERT INTO t1 VALUES('B','012,345');
    INSERT INTO t1 VALUES('C','678,901,234');
    SELECT col1, col2, pos, pre, SUBSTR(col2, pre+1, pos-pre-1) token FROM (
    SELECT row_num, col1, col2, decode(pos,0,LENGTH(col2)+1,pos) pos, pre FROM (
    SELECT row_num, col1, col2, pos, nvl(LAG(pos) OVER (PARTITION BY col1 ORDER BY row_num),0) pre
    FROM (
    SELECT row_num, vw.col1, vw.col2, INSTR(vw.col2,',',1,row_num) pos
    FROM (
    SELECT ROWNUM row_num FROM (
    SELECT LEVEL FROM dual connect by LEVEL <= 5
    )) r,
    (SELECT col1, col2 FROM t1) vw
    WHERE pos <> 0 OR pre <> 0
    i think some part it may be help u also

  • How to convert rows to columns in sql server 2008

    How to convert rows to columns in sql server 2008 using the GROUP BY function? (only one query allowed)

    Lookup the Pivot transformation. From BOL:
    The Pivot transformation makes a normalized data set into a less normalized
    but more compact version by pivoting the input data on a column value. For
    example, a normalized Orders data set that lists customer name, product, and quantity purchased typically has multiple rows for any customer who purchased multiple products, with each row for that customer showing order
    details for a different product. By pivoting the data set on the product column, the Pivot transformation can output a data set with a
    single row per customer. That single row lists all the purchases by the customer, with the product names shown as column names, and the quantity shown as a value in the product column. Because not every customer purchases every product, many columns may contain
    null values.
    When a dataset is pivoted, input columns perform different roles in the pivoting process. A column can participate in the following ways:
    The column is passed through unchanged to the output. Because many input rows
    can result only in one output row, the transformation copies only the first
    input value for the column.
    The column acts as the key or part of the key that identifies a set of
    records.
    The column defines the pivot. The values in this column are associated with
    columns in the pivoted dataset.
    The column contains values that are placed in the columns that the pivot
    creates.
    Paul

  • How to convert rows into columns

    Hi,
    How to convert rows into columns of two different tables.
    These two tables have two common columns namely (shipline,pos).
    Let me know if we have any built in functions to do this.
    thank you very much .
    Edited by: 808542 on Dec 7, 2010 8:35 PM
    Edited by: 808542 on Dec 7, 2010 8:37 PM

    Have you tried this first?
    http://forums.oracle.com/forums/search.jspa?threadID=&q=row+to+column&objID=f75&dateRange=last90days&userID=&numResults=15&rankBy=10001

  • How to convert rows into columns with decode function

    Hi,
    How to convert rows into columns with the help of decode function in oracle.
    thanks and regards
    P Prakash

    say
    col1 col2
    1 10
    2 20
    3 30
    then use
    select col1,
    sum(decode(col2,10,10)) "new1"
    sum(decode(col2,20,20))"new2"
    sum(decode(col2,30,30))"new3"
    from table_name
    group by col1;
    we used sum u can use ny function if wont u have to give the column name i.e col2 name also
    so i think u got it nw
    regards

  • How to convert rows into column

    Hi,
    can any one help me how to convert rows into column by pl/sql procedure.
    Thanks and Regards

    http://www.oracle.com/technology/oramag/code/tips2004/050304.html
    -- dropping the sample table if exists
    drop table rowstocol
    -- create sample table
    create table rowstocol ( name varchar2(20));
    -- Inserting rows into sample table
    insert into rowstocol values('Amit Zhankar');
    insert into rowstocol values('Piyu Yawalkar');
    insert into rowstocol values('Piyu Yawalkar');
    insert into rowstocol values('Ashish Ghelani');
    insert into rowstocol values('Aditi Zhankar');
    insert into rowstocol values('Tom Kyte');
    insert into rowstocol values('Oracle');
    -- Following query should be run to create a sql. This result sql should be run to convert rows to column.
    -- The following query uses just the tablename (whose data is to be converted) and name of the column (which is to be converted).
    -- Example taken here is table rowstocol, column name.
    SELECT cc
    FROM (select decode(rn ,1 ,'Select ',null) ||' MAX (CASE WHEN dr = '|| rownum||' THEN DECODE (rn,1, col1) END) '||
    decode(rn,maxr,' col1 from ','||'||chr(39)||','||chr(39)||'|| ') cc,rn,maxr
    from (SELECT ROWNUM rn,count(0) over() maxr FROM rowstocol) order by rn) trows
    union all
    select '(SELECT tabs.col1, DENSE_RANK () OVER (ORDER BY col1,rowid) dr,dense_rank() OVER (order by 1) rn
    FROM (SELECT NAME col1 FROM rowstocol) tabs ) group by rn' cc from dual;
    -- The result of this query will do the reqd conversion from row to column.
    -- Replace table rowstocol by your table, column name by your column.
    CC
    Select MAX (CASE WHEN dr = 1 THEN DECODE (rn,1, col1) END) ||','||
    MAX (CASE WHEN dr = 2 THEN DECODE (rn,1, col1) END) ||','||
    MAX (CASE WHEN dr = 3 THEN DECODE (rn,1, col1) END) ||','||
    MAX (CASE WHEN dr = 4 THEN DECODE (rn,1, col1) END) ||','||
    MAX (CASE WHEN dr = 5 THEN DECODE (rn,1, col1) END) ||','||
    MAX (CASE WHEN dr = 6 THEN DECODE (rn,1, col1) END) ||','||
    MAX (CASE WHEN dr = 7 THEN DECODE (rn,1, col1) END) ||','||
    MAX (CASE WHEN dr = 8 THEN DECODE (rn,1, col1) END) col1 from
    (SELECT tabs.col1, DENSE_RANK () OVER (ORDER BY col1,rowid) dr,dense_rank() OVER (order by 1) rn
    FROM (SELECT NAME col1 FROM rowstocol) tabs ) group by rn
    Select MAX (CASE WHEN dr = 1 THEN DECODE (rn,1, col1) END) ||','||
    MAX (CASE WHEN dr = 2 THEN DECODE (rn,1, col1) END) ||','||
    MAX (CASE WHEN dr = 3 THEN DECODE (rn,1, col1) END) ||','||
    MAX (CASE WHEN dr = 4 THEN DECODE (rn,1, col1) END) ||','||
    MAX (CASE WHEN dr = 5 THEN DECODE (rn,1, col1) END) ||','||
    MAX (CASE WHEN dr = 6 THEN DECODE (rn,1, col1) END) ||','||
    MAX (CASE WHEN dr = 7 THEN DECODE (rn,1, col1) END) ||','||
    MAX (CASE WHEN dr = 8 THEN DECODE (rn,1, col1) END) col1 from
    (SELECT tabs.col1, DENSE_RANK () OVER (ORDER BY col1,rowid) dr,dense_rank() OVER (order by 1) rn
    FROM (SELECT NAME col1 FROM rowstocol) tabs ) group by rn;
    COL1
    Aditi Zhankar,Amit Zhankar,Ashish Ghelani,Oracle,Oracle,Piyu Yawalkar,Piyu Yawalkar,Tom Kyte
    Edited by: bhooma on Jan 20, 2009 2:44 AM

  • How to get multiple records in one row and different column

    Hi All,
    I am using oracle database 11g
    and i have a two tables table_1, table_2
    table_1 having columns
    emp_no
    first_name
    middle_name
    last_name
    email
    and table_2 having columns
    emp_no
    phone_type
    phone_number
    and having entires
    emp_no phone_type phone_number
    1001 MOB 9451421452
    1001 WEMG 235153654
    1001 EMG 652341536
    1002 MOB 9987526312
    1003 WEMG 5332621456
    1004 EMG 59612356
    Now i want the output of values with phone type as MOB or WEMG in a single row with different columns
    emp_no first_name middle_name last_name email mobile officeno
    1001 mark null k [email protected] 9451421452 235153654
    1002 john cena gary [email protected] 9987526312 null
    1003 dany null craig [email protected] null 5332621456
    1004 donald finn sian [email protected] null null
    can i have any inputs to achive this???
    Regards
    $sid

    Frank Kulash wrote:
    sonething like this:Frank, you missed aggregate function (pivot requires one). However main thing is it will cause ORA-01748:
    with table_1 as (
                     select 1001 emp_no,'mark' first_name,null middle_name,'k'last_name,'[email protected]' email from dual union all
                     select 1002,'john','cena','gary','[email protected]' from dual union all
                     select 1003,'dany',null,'craig','[email protected] null' from dual union all
                     select 1004,'donald','finn','sian','[email protected]' from dual
         table_2 as (
                     select 1001 emp_no,'MOB' phone_type,9451421452 phone_number from dual union all
                     select 1001,'WEMG',235153654 from dual union all
                     select 1001,'EMG',652341536 from dual union all
                     select 1002,'MOB',9987526312 from dual union all
                     select 1003,'WEMG',5332621456 from dual union all
                     select 1004,'EMG',59612356 from dual
    SELECT     *
    FROM     table_1      t1
    JOIN     table_2      t2  ON  t1.emp_no = t2.emp_no
    PIVOT     (    max(t2.phone_number)
         FOR  t2.phone_type  IN  ( 'MOB'   AS mob
                                 , 'WEMG'  AS wemg
            FOR  t2.phone_type  IN  ( 'MOB'   AS mob
    ERROR at line 19:
    ORA-01748: only simple column names allowed hereYou need to:
    with table_1 as (
                     select 1001 emp_no,'mark' first_name,null middle_name,'k' last_name,'[email protected]' email from dual union all
                     select 1002,'john','cena','gary','[email protected]' from dual union all
                     select 1003,'dany',null,'craig','[email protected] null' from dual union all
                     select 1004,'donald','finn','sian','[email protected]' from dual
         table_2 as (
                     select 1001 emp_no,'MOB' phone_type,9451421452 phone_number from dual union all
                     select 1001,'WEMG',235153654 from dual union all
                     select 1001,'EMG',652341536 from dual union all
                     select 1002,'MOB',9987526312 from dual union all
                     select 1003,'WEMG',5332621456 from dual union all
                     select 1004,'EMG',59612356 from dual
         table_3 as (
                     select  t1.emp_no,first_name,middle_name,last_name,email,
                             phone_type,phone_number
                       FROM     table_1      t1
                       LEFT JOIN     table_2      t2  ON  t1.emp_no = t2.emp_no
    SELECT     *
    FROM     table_3
    PIVOT     (    max(phone_number)
         FOR  phone_type  IN  ( 'MOB'   AS mob
                                 , 'WEMG'  AS wemg
        EMP_NO FIRST_ MIDD LAST_ EMAIL                     MOB       WEMG
          1004 donald finn sian  [email protected]
          1003 dany        craig [email protected] null            5332621456
          1001 mark        k     [email protected]      9451421452  235153654
          1002 john   cena gary  [email protected]    9987526312
    SQL>SY.

  • Different number of rows for different columns in JTable

    hi
    I need to create a JTable with different number of rows for different columns...
    Also the rowheight should be different in each column...
    say there is a JTable with 2 columns... Col1 having 5 rows and column 2 having 2 rows...
    The rowHeight in Col2 should be an integer multiple of Rowheight in Col1
    how do I do this ??
    can anybody send me some sample code ?????
    thanx in advance

    How about nesting JTables with 1 row and many columns in a JTable with 1 column and many rows.
    Or you could leave the extra columns null/blank.
    You could use a GridBagLayout and put a panel in each group of cells and not use JTable at all.
    It would help if you were more specific about how you wanted it to appear and behave.

  • How to convert row into column

    Hi All,
    My oracle apps version is r12 and db is 10 and i am using Bi publisher version 10g.
    Is it possible to convert row into column in Rtf template,
    My Query is
    SELECT distinct pvs.vendor_site_code,sum(aia.invoice_amount)
    FROM ap_invoices_all aia, po_vendors po, po_vendor_sites_all pvs
    WHERE aia.org_id = pvs.org_id
    AND aia.vendor_id = po.vendor_id
    AND aia.vendor_site_id = pvs.vendor_site_id
    AND aia.org_id=204
    group by pvs.vendor_site_code
    And output is like this
    Vendor sitecode Invoiceamt
    EAM-ERS 79240
    STAR GATE - PAY 3245902.31
    UPS - HQ 10792040.9
    Like this
    So in template i need the output like this
    Vendor sitecode EAM-ERS STAR GATE - PAY UPS - HQ
    Invoiceamt 79240 3245902.31 10792040.9
    I tried to achieve the output using sql query but by hardcoding only i have achieved it, so i have tried to convert directly in RTF template.
    can any one tell me is it possible.
    And if new project is added from the front end ie(now the query will produce 4 rows but now in template i have created only three columns)
    Is it possible to add a new column dynamically.
    Can any one please guide me and tell me is there any example.
    Thanks & regards
    Srikkanth

    Take a look at this post: http://blogs.oracle.com/roller-ui/bsc/spider.jsp?entry=MT%3aENTRY%3a5001
    Thanks,
    Bipuser

  • How to convert rows to columns of a table?

    I want to convert rows to columns of a table..
    Query in SQL??

    965373 wrote:
    I want to convert rows to columns of a table..
    Query in SQL??PIVOT by Frank Help for a query to add columns
    PIVOT by TomK http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:766825833740

  • Changing rows into different column names

    Hi,
    i need to tranpose the rows into differnent column names
    my sample data :
    id , val
    1 3
    1 4
    1 5
    into
    id , val1, val2 , val3 , val4 ... valn ..
    1 3 4 5
    from askTom's i see that it's tranpose into a single column using the ref cursor ?
    how can i do made it into different column names ?
    kindly advise
    tks & rdgs

    For example, lets say that you want to order your columns from least value to greatest and that you'll never have more than three values per id. Then you can use the analytic function row_number() like this to create a pivot value.
    select id, val,
           row_number() over (partition by id order by val) as rn
      from your_table;And so your pivot query ends up looking like this.
    select id,
           max(case when rn=1 then val end) AS val1,
           max(case when rn=2 then val end) AS val2,
           max(case when rn=3 then val end) AS val3
      from (
    select id, val,
           row_number() over (partition by id order by val) as rn
      from your_table
    group by id;But notice that I started out by making up answers to Justin's questions. You'll have to supply the real answers.

  • How to filter rows where multiple columns meet criteria, ignoring rows where only some columns meet criteria

    Hi All,
    Question: How do I filter rows out of a query where multiple columns are equal to a single question mark character?
    Background: I'm using SQL 2008 R2.  Furthermore, the part of my brain that helps me create less-than-simple queries hasn't been working for the last 4 days, apparently, and now I need help.
    We have about 4,000 rows in a table.  This data set was generated from an exported report, and many of the rows in the detail table were not actual data rows but were simply "header" rows.  For those table rows, most of the columns have
    a single question mark as the value.
    Some of the detail rows have one or more question mark values, too, so it's important that these rows don't get filtered out.
    When I include criteria like "WHERE col1 <> '?' AND col2 <> '?' AND col3 <> '?' AND col4 <> '?'", all rows with a question mark value for even a single one of those columns get filtered out.  How do I filter out rows
    where all columns 1-4 contain a question mark value?
    Thanks for your help,
    Eric

    I just tried to create to create a scenario for you. Please see ig you're looking for something like this.
    Create table test_Question_mark
    RecordID INT identity(1,1),
    Col1 varchar(10),
    Col2 varchar(10),
    Col3 varchar(10),
    Col4 varchar(10),
    insert into test_Question_mark (Col1, Col2, Col3, col4) values ('?','?','?','?')
    insert into test_Question_mark (Col1, Col2, Col3, col4) values ('?','??','?','?')
    insert into test_Question_mark (Col1, Col2, Col3, col4) values ('?','??','??','?')
    insert into test_Question_mark (Col1, Col2, Col3, col4) values ('??','??','??','??')
    insert into test_Question_mark (Col1, Col2, Col3, col4) values ('?','?','?','?')
    insert into test_Question_mark (Col1, Col2, Col3, col4) values ('??','test ??','??','??')
    insert into test_Question_mark (Col1, Col2, Col3, col4) values ('??','test ?','??','??')
    --drop table test_Questio_mark
    select * from test_Question_mark
    select * from test_Question_mark 
    WHERE 
    (CHARINDEX('?', Col1,1) > 0 AND CHARINDEX('?', Col1, CHARINDEX('?', Col1,1)+1) = 0) AND 
    (CHARINDEX('?', Col2) > 0 AND CHARINDEX('?', Col2, CHARINDEX('?', Col2,1)+1) = 0) AND 
    (CHARINDEX('?', Col3,1) > 0 AND CHARINDEX('?', Col3, CHARINDEX('?', Col3,1)+1) = 0) AND 
    (CHARINDEX('?', Col4,1) > 0 AND CHARINDEX('?', Col4, CHARINDEX('?', Col4,1)+1) = 0) 
    --drop table test_Questio_mark
    I hope above solution will help.
    Thanks!
    Ashish.

  • How to suppress row when one column has zero  using condition

    Hi Experts,
    How do I suppress row when one column has zero.
    I read it is possible using conditions.
    How ?
    Thankyou.

    Check this
    1. for Query Properties, go to the Display tab and Supress Zeros is "Active"
    2. select the Structure, right-click, select Properties, then click "on" Also Use Zero Suppression for Structure Elements
    http://help.sap.com/saphelp_nw04/helpdata/en/a4/dd3841d132d92be10000000a1550b0/frameset.htm
    Hope it Helps
    Chetan
    @CP..

Maybe you are looking for

  • How do I get back PHOTOSHOP TOOLS in Bridge CS5.1?

    I used the PHOTOSHOP option under TOOLS in Bridge CS5 all the time.  I upgraded my InDesign to CS5.5 and with it I was automatically upgraded to Bridge CS5.1 but now ther is no longer a PHOTOSHOP option under TOOLS.  When I try to open the older Brid

  • HT1338 The screen on My mac book pro goes black for no reason if I use the f1 and f2 keys it comes back

    My screen on my mac book pro goes blank for no reason when I use f1 and f2 keys it comes back

  • Problem with accessing database

    Hi everybody I try to execute some wars included with the J2EE tutorial final version and I follow all the steps in building and deploying the specified wars, some of those wars is a punch of JSP pages and Servlet that make access to database. When I

  • Reload of composite on server restart

    Hi, We have a processes which is invoking some 5 to 6 other bpel processes.On server restart this dependent process is getting loaded first ,i.e prior to the load of other bpel processes.So the reload is failing with : The composite OrderRespOAppProc

  • Old Contacts Appearing - Windows, Outlook

    This is odd. I am having some other syncing problems, which should be cured (Apple says) when I upgrade Outlook to the latest version. BUT, this is interesting. My Contacts do in fact seem to sync fine. Looking through them, I see contacts that are m