How to convert rows into columns in sql server?

Hi All,
I have table called table1 which contains the below information
Projectname           Weeks       Work
p1                          w5            200
p1                          w6            300
p1                          w7            234
p2                          w5            765
p2                          w6            987
p3                          w1            976
p3                          w2            231
I need to pivot this table. I need the info like below
Projectname          w1        w2          w5          w6       
w7
p1                                                  
200        300        234
p2                                                  
765         987
p3                        976       231
How can I make like this?

One more way,
create table #temp(Projectname varchar(10),Weeks varchar(10), Work int)
insert into #temp values('p1','w5',200)
insert into #temp values('p1','w6',300)
insert into #temp values('p1','w7',234)
insert into #temp values('p2','w5',765)
insert into #temp values('p2','w6',987)
insert into #temp values('p3','w1',976)
insert into #temp values('p3','w2',231)
Select ProjectName,
Sum(Case when Weeks = 'W1' Then Work Else NULL End) W1,
Sum(Case when Weeks = 'W2' Then Work Else NULL End) W2,
Sum(Case when Weeks = 'W3' Then Work Else NULL End) W3,
Sum(Case when Weeks = 'W4' Then Work Else NULL End) W4,
Sum(Case when Weeks = 'W5' Then Work Else NULL End) W5,
Sum(Case when Weeks = 'W6' Then Work Else NULL End) W6,
Sum(Case when Weeks = 'W7' Then Work Else NULL End) W7
From #temp
Group by ProjectName
Drop table #temp

Similar Messages

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

  • Convert Rows to Columns In Sql Server

    If my Table look something like this
    Create Table #Temp(Id Int, Name VarChar(20), Value VarChar(20))
    Insert Into #Temp Values(1, 'Name','George')
    Insert Into #Temp Values(1, 'ShoeSize','9.5')
    Insert Into #Temp Values(1, 'Name','Gkjdk')
    Insert Into #Temp Values(1, 'ShoeSize','8.9')
    Insert Into #Temp Values(2, 'Name','Bill')
    Insert Into #Temp Values(2, 'ShoeSize','10.5')
    Insert Into #Temp Values(3, 'Name','John')
    Insert Into #Temp Values(3, 'ShoeSize','9')
    Insert Into #Temp Values(4, 'Name','Greg')
    Insert Into #Temp Values(4, 'ShoeSize','9')
    and its output is like this
    id name value 
    1 Name  George
    1 Shoesize 9.5
    1 Name   Gkjdk
    1 Shoesize 8.9
    2 Name  Bill 
    2 Shoesizr  10.5
    I want my result in this format
    id Name Shoesize
    1   George 9.5
    1   Gkjdk    8.9
    2     Bill      10.5
    I tried pivot function but it will not work it only first row for id 1 bcoz of aggregate function used and i also used group by that also nt work if any one has suggesstions plz help.
    Select Id,
           Min(Case When Name = 'Name' Then Value End) As Name,
           Min(Case When Name = 'ShoeSize' Then Value End) As ShoeSize
    From   #Temp
    Group By Id
    Id is not the primary key my scenario is something like that but that actual data is not like that

    Hello ,
    A common scenario where PIVOT can be useful is when you want to generate cross-tabulation reports to summarize data. For example, suppose you want to query the
    PurchaseOrderHeader table in the
    AdventureWorks2008R2 sample database to determine the number of purchase orders placed by certain employees. The following query provides this report, ordered by vendor.
    Copy
    USE AdventureWorks2008R2;
    GO
    SELECT VendorID, [250] AS Emp1, [251] AS Emp2, [256] AS Emp3, [257] AS Emp4, [260] AS Emp5
    FROM
    (SELECT PurchaseOrderID, EmployeeID, VendorID
    FROM Purchasing.PurchaseOrderHeader) p
    PIVOT
    COUNT (PurchaseOrderID)
    FOR EmployeeID IN
    ( [250], [251], [256], [257], [260] )
    ) AS pvt
    ORDER BY pvt.VendorID;
    Here is a partial result set.
    VendorID    Emp1        Emp2        Emp3        Emp4        Emp5
    1492        2           5           4           4           4
    1494        2           5           4           5           4
    1496        2           4           4           5           5
    1498        2           5           4           4           4
    1500        3           4           4           5           4
    The results returned by this subselect statement are pivoted on the
    EmployeeID column.
    Ref : MSDN
    Ahsan Kabir Please remember to click Mark as Answer and Vote as Helpful on posts that help you. This can be beneficial to other community members reading the thread. http://www.aktechforum.blogspot.com/

  • Convert rows into columns nad vice versa in 10g

    how to convert rows into columns in 10g??

    Qwerty wrote:
    see below for rows to column case
    SQL> WITH t as
    2      (
    3       SELECT 'US' test_string FROM DUAL UNION
    4       SELECT 'AMERICA'  FROM DUAL UNION
    5       SELECT'HOLLYWOOD'  FROM DUAL UNION
    6       SELECT 'WASHINGTON'  FROM DUAL
    7      )
    8      select ltrim (sys_connect_by_path(test_string,','),',') test_string
    9        from (
    10     SELECT row_number() over(order by test_string) rno, test_string
    11       FROM t)
    12       WHERE connect_by_isleaf = 1 and rownum=1
    13       connect by rno = prior rno+1;
    TEST_STRING
    AMERICA,HOLLYWOOD,US,WASHINGTONI hope you can do it for column to rows now.That's not really rows to columns. That's rows to a column, which is more commonly called string aggregation.
    Rows to columns (or pivot) is more like:
    SQL> ed
    Wrote file afiedt.buf
      1  WITH t as
      2       (
      3        SELECT 'US' test_string FROM DUAL UNION
      4        SELECT 'AMERICA'  FROM DUAL UNION
      5        SELECT'HOLLYWOOD'  FROM DUAL UNION
      6        SELECT 'WASHINGTON'  FROM DUAL
      7       )
      8  --
      9  select max(decode(rn,1,test_string)) as col_1
    10        ,max(decode(rn,2,test_string)) as col_2
    11        ,max(decode(rn,3,test_string)) as col_3
    12        ,max(decode(rn,4,test_string)) as col_4
    13* from (select test_string, row_number() over (order by test_string) as rn from t)
    SQL> /
    COL_1      COL_2      COL_3      COL_4
    AMERICA    HOLLYWOOD  US         WASHINGTON
    SQL>And columns to rows (or unpivot) is like:
    SQL> ed
    Wrote file afiedt.buf
      1  WITH t as
      2       (
      3        SELECT 'US' col_1, 'AMERICA' col_2, 'HOLLYWOOD' col_3, 'WASHINGTON' col_4 FROM DUAL
      4       )
      5  --
      6  select col_1 as col from t union all
      7  select col_2 from t union all
      8  select col_3 from t union all
      9* select col_4 from t
    SQL> /
    COL
    US
    AMERICA
    HOLLYWOOD
    WASHINGTONor...
    SQL> ed
    Wrote file afiedt.buf
      1  WITH t as
      2       (
      3        SELECT 'US' col_1, 'AMERICA' col_2, 'HOLLYWOOD' col_3, 'WASHINGTON' col_4 FROM DUAL
      4       )
      5  --
      6  select decode(rownum,1,col_1,2,col_2,3,col_3,4,col_4) as col
      7* from t, (select * from dual connect by rownum <= 4)
    SQL> /
    COL
    US
    AMERICA
    HOLLYWOOD
    WASHINGTON
    SQL>

  • Converting Rows into Column in Oracle 10g

    Hi All,                    
    I m using Oracle Version 10.1.0.2.0 - Production                    
    I have requirement to convert rows into column wise as per the following:                    
    My Query is:                    
    WITH t                    
    AS ( SELECT 'A' AS x, 100 AS y FROM DUAL                     
    UNION ALL                    
    SELECT 'B',200 FROM DUAL                    
    SELECT X, Y                    
    FROM t;     
    X Y
    A 100
    B 200
    My Requirement is
    A B
    100 200
    So any one could help me that how I resolve this.
    Regards,
    Prasanta

    Dear frank,
    Thanks for your support,.
    It's working fine for static cases.If the first column is dynamic then how come i will resolve it.
    Example:
    Create table mytab (ID_C Varchar2(15),Value_N Number);
    Records Population into MyTab table is dynamic.
    Insert into mytab values('HO',5000);
    Insert Into mytab values('PG1',2400);
    Insert Into mytab values('PG2',3000);
    Insert Into mytab values('PG3',800);
    Commit;
    SQL> Select * From MyTab;
    IDC_ ValueN_
    HO 5000
    PG1 2400
    PG2 3000
    PG3 800
    Then My expected result will be as follows
    HO PG1 PG2 PG3
    5000 2400 3000 800
    Thanks and Regards,
    Prasanta

  • CONVERT ROWS INTO COLUMNS IN INTERNAL TABLE

    Hi Experts,
    I want to convert rows into coloumns in final internal table.
    How to do that one. Can any one help me its very urgent.
    Regards,
    PBS.

    hi,
    Find the below code for changing rows into colums.
    data: begin of itab1 occurs 0,
    fld,
    end of itab1.
    data: begin of itab2 occurs 0,
    fld1,
    fld2,
    fld3,
    end of itab2.
    itab1-fld = 1.
    append itab1.
    itab1-fld = 2.
    append itab1.
    itab1-fld = 3.
    append itab1.
    read table itab1 index 1.
    if sy-subrc eq 0.
    itab2-fld1 = itab1-fld.
    endif.
    read table itab1 index 2.
    if sy-subrc eq 0.
    itab2-fld2 = itab1-fld.
    endif.
    read table itab1 index 3.
    if sy-subrc eq 0.
    itab2-fld3 = itab1-fld.
    endif.
    append itab2.
    loop at itab1.
    write:/ itab1.
    endloop.
    loop at itab2.
    write:/ itab2.
    endloop.
    refer the below link for further information
    internal table rows to columns
    in the final display list how can i change rows to columns and vice versa

  • How to Convert Rows to Column in Query

    Dear All,
    I'm having problems in converting the data from rows into columns. Eg:
    - item A sold on 01/01/07 = 5 kg
    - item A sold on 10/01/07 = 5 kg
    total item A sold in "JAN" = 10kg
    - item A sold on 01/03/07 = 20 kg
    total item A sold in "Mar" = 20kg
    I did a query and it appear as below (in which I need the period as column)
    Item Qty Period
    A 10 2007-01
    A 20 2007-03
    The output I need is :
    Item Jan Feb Mar
    A 10 - 20
    I've refer to the query posted in "Item History Query", even though I can get the column from Jan - Dec, but the total quantity for each month is not accurate. Please advise, and thanks for your time.
    Cheers,
    Serene

    Hello Serene,
    The Quantities will not be correct because you are using a Period Code in the Selection Criteria but it is not checked in the Select Statement. 
    But rewriting the code would cause duplicate entries for each item per months because of how the Group by clause works.
    CHECK THIS
    SELECT T1.ItemCode, T1.Dscription,
    (SELECT SUM(QUANTITY) FROM INV1 WHERE MONTH(DOCDATE) = 1 AND ITEMCODE = T1.ItemCode AND DOCDATE >= T2.F_RefDate AND DOCDATE <= T_RefDate) AS 'JAN',
    (SELECT SUM(QUANTITY) FROM INV1 WHERE MONTH(DOCDATE) = 2 AND ITEMCODE = T1.ItemCode AND DOCDATE >= T2.F_RefDate AND DOCDATE <= T_RefDate) AS 'FEB',
    (SELECT SUM(QUANTITY) FROM INV1 WHERE MONTH(DOCDATE) = 3 AND ITEMCODE = T1.ItemCode AND DOCDATE >= T2.F_RefDate AND DOCDATE <= T_RefDate) AS 'MAR',
    (SELECT SUM(QUANTITY) FROM INV1 WHERE MONTH(DOCDATE) = 4 AND ITEMCODE = T1.ItemCode AND DOCDATE >= T2.F_RefDate AND DOCDATE <= T_RefDate) AS 'APR',
    (SELECT SUM(QUANTITY) FROM INV1 WHERE MONTH(DOCDATE) = 5 AND ITEMCODE = T1.ItemCode AND DOCDATE >= T2.F_RefDate AND DOCDATE <= T_RefDate) AS 'MAY',
    (SELECT SUM(QUANTITY) FROM INV1 WHERE MONTH(DOCDATE) = 6 AND ITEMCODE = T1.ItemCode AND DOCDATE >= T2.F_RefDate AND DOCDATE <= T_RefDate) AS 'JUN',
    (SELECT SUM(QUANTITY) FROM INV1 WHERE MONTH(DOCDATE) = 7 AND ITEMCODE = T1.ItemCode AND DOCDATE >= T2.F_RefDate AND DOCDATE <= T_RefDate) AS 'JUL',
    (SELECT SUM(QUANTITY) FROM INV1 WHERE MONTH(DOCDATE) = 8 AND ITEMCODE = T1.ItemCode AND DOCDATE >= T2.F_RefDate AND DOCDATE <= T_RefDate) AS 'AUG',
    (SELECT SUM(QUANTITY) FROM INV1 WHERE MONTH(DOCDATE) = 9 AND ITEMCODE = T1.ItemCode AND DOCDATE >= T2.F_RefDate AND DOCDATE <= T_RefDate) AS 'SEP',
    (SELECT SUM(QUANTITY) FROM INV1 WHERE MONTH(DOCDATE) = 10 AND ITEMCODE = T1.ItemCode AND DOCDATE >= T2.F_RefDate AND DOCDATE <= T_RefDate) AS 'OCT',
    (SELECT SUM(QUANTITY) FROM INV1 WHERE MONTH(DOCDATE) = 11 AND ITEMCODE = T1.ItemCode AND DOCDATE >= T2.F_RefDate AND DOCDATE <= T_RefDate) AS 'NOV',
    (SELECT SUM(QUANTITY) FROM INV1 WHERE MONTH(DOCDATE) = 12 AND ITEMCODE = T1.ItemCode AND DOCDATE >= T2.F_RefDate AND DOCDATE <= T_RefDate) AS 'DEC',
    (SELECT SUM(QUANTITY) FROM INV1 WHERE ITEMCODE = T1.ItemCode AND DOCDATE >= T2.F_RefDate AND DOCDATE <= T_RefDate) AS 'TOTAL'
    FROM OINV T0 INNER JOIN INV1 T1 ON T0.DocEntry = T1.DocEntry INNER JOIN OFPR T2 ON T0.FinncPriod = T2.AbsEntry
    WHERE T0.CardName ='[%A]' AND T2.Code >='[%1]' AND T2.Code <='[%2]'
    GROUP BY T1.ItemCode, T1.Dscription, T2.F_RefDate, T2.T_RefDate
    The Only way out of this is to declare Variable and Assign the F_RefDate and T_RefDate and then use the variables in the Select Statements.
    Suda

  • How to transpose rows into columns?

    How do I transpose all rows into columns like how excel does?
    For example:
    declare @t table (ProductID int, Type varchar(20), Name varchar(20), isAvailable bit)
    insert into @t 
    select 1, 'Type1', 'Product1',1
    union
    select 2, 'Type1', 'Product2',0
    union
    select 3, 'Type2', 'Product3',1
    union
    select 4, 'Type2', 'Product4',0
    Results to:
    ProductID Type
    Name isAvailable
    1 Type1
    Product1 1
    2 Type1
    Product2 0
    3 Type2
    Product3 1
    4 Type2
    Product4 0
    What I need is:
    1
    2
    3
    4
    Type1
    Type1
    Type2
    Type2
    Product1
    Product2
    Product3
    Product4
    1
    0
    1
    0
    Where 1,2,3,4 at the top are the columns.

    select 
    max(case when Type='Type1' and name ='Product1' then Type end) [1],
    max(case when Type='Type1' and name ='Product2' then Type end) [2],
    max(case when Type='Type2' and name ='Product3' then Type end) [3],
    max(case when Type='Type2' and name ='Product4' then Type end) [4]
    from @t
    union all
    select 
    max(case when Type='Type1' and name ='Product1' then Name end) [1],
    max(case when Type='Type1' and name ='Product2' then Name end) [2],
    max(case when Type='Type2' and name ='Product3' then Name end) [3],
    max(case when Type='Type2' and name ='Product4' then Name end) [4]
    from @t
    union all
    select 
    max(case when Type='Type1' and name ='Product1' then cast(isAvailable as varchar(5)) end) [1],
    max(case when Type='Type1' and name ='Product2' then cast(isAvailable as varchar(5)) end) [2],
    max(case when Type='Type2' and name ='Product3' then cast(isAvailable as varchar(5)) end) [3],
    max(case when Type='Type2' and name ='Product4' then cast(isAvailable as varchar(5)) end) [4]
    from @t
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • Convert row into columns

    Hello World ,
    I want to make the below table data come in one row
    Name | code | MARK
    AAA | CODE2 | 50
    AAA | CODE1 | 30
    AAA | CODE3 | 22
    BBB | CODE2 | 52
    BBB | CODE3 | 53
    CCC | CODE3 | 11
    AES | CODE1 | 75
    FES | CODE2 | 44
    i want it to be like this
    NAME | CODE1 | CODE2 | CODE3
    AAA | 30 | 30 | 22
    BBB | - | 52 | 53
    CCC | - | - | 11
    is there another way of DECODE?
    Regards

    A very small amount of effort on your side would have found the FAQ thread "How do I convert rows to columns" SQL and PL/SQL FAQ

  • How to convert rows to columns

    Hi there,
    DB version Oracle 11g.
    this is my query ;
    select TO_CHAR(R_TARIHI, 'DAY'), TO_CHAR(T.BASLAMA,'HH24:MI') AS SAAT,(h.adi || ' ' ||h.soyadi) as HASTA
    from randevu_entegre t left outer join hasta h on h.id=t.hasta_id
    left outer join kod_randevu_turleri kr on kr.id=1
    where (R_TARIHI between to_Date('20.5.2011','dd.MM.yyyy') and (to_Date('20.5.2011','dd.MM.yyyy')+8))
    and (TO_CHAR(R_TARIHI, 'DY') NOT IN ('CMT','PAZ') )
    and DOKTOR_ID=224 order by t.baslama
    results table in this form                                          
    CUMA   
    13:30
    ORHAN SAVAS
    CUMA   
    14:00
    FATMA ETA
    CUMA   
    14:30
    ISMAHAN YALDIZ
    PAZARTESI
    13:00
    SEYHAN UNVER
    PAZARTESI
    13:30
    SELMA CALISKAN
    PAZARTESI
    17:45
    ESMA COMERT
    SALI   
    09:45
    SEYMA DURLANIK
    SALI   
    10:00
    HASAN GOC
    SALI   
    13:00
    TURKAN BICAK
    SALI   
    14:30
    ISMAHAN YALDIZ
    PERSEMBE
    08:30
    ZUHRE YEL
    PERSEMBE
    08:48
    AYSEL POLAT
    PERSEMBE
    09:00
    AHMET OZGUNGOR
    PERSEMBE
    09:12
    TELEFON RANDEVUSU
    can I convert my results table like this? Please help me.
    CUMA
    PAZARTESI
    SALI    
    PERSEMBE
    13:30 ORHAN SAVAS
    13:00 SEYHAN UNVER
    09:45 SEYMA DURLANIK
    08:30 ZUHRE YEL
    14:00 FATMA ETA
    13:30 SELMA CALISKAN
    10:00 HASAN GOC
    08:48 AYSEL POLAT
    14:30 ISMAHAN YALDIZ
    17:45 ESMA COMERT
    13:00 TURKAN BICAK
    09:00 AHMET OZGUNGOR
    14:30 ISMAHAN YALDIZ
    09:12 TELEFON RANDEVUSU

    hi Sarma,
    i visited to the link given by you & also reviewed the problems.but the question still in mind,with decode we can covert rows into columns but only where we have finite no of values in the row for eg. in deptno. we have just 4 types of values i.e. 10-40...
    but in case we have more than 20 distinct values in row & we have to make 20 column name from those 20 row values then we need 20 decode statements which is a lengthy process..do you have some other alternative regarding this.
    regards,
    Bhupinder Singh

  • 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

Maybe you are looking for

  • Problem while opening PDF attachment in Inbox

    Hi all, I am sending PDF attachment through email to inbox. When am trying to open PDF attachment i am getting error- 'There was an eror opening this document.The fuile changed and couldnt be open' When i click on attachment some bytes are getting tr

  • How can i find my phone without the find my iPhone app?

    i lost my iphone while going to a car my friends say that it might of dropped in the floor i said maybe in the car i checked everywhere in the car and i cant find it. My moms sim is in my phone we have the same number yet no one can call or send me a

  • Channel table to table

    Hi All, I would like to Fill in a Table in the SUD with  a Channel Data (more than 20000 rows)  I was trying with a loop  which takes more than 3 mins to fill the table and display it .I just need to consider the real data NOVALUES are not taken in t

  • Reporting of Child Routed Calls Using Parent TCD table

                       The TCD records of Parent do not show RoutID, ServiceSkillTargetID filed for calls routed by Child ucce. The Calltype ID filed shows "-1" for all such records. The dbo Service Table in parent is correctly populated and contains all

  • Can the B210 Print on both sides?

    I have an Photosmart Plus e-All-in-One Printer - B210a running on Windows Vista on an Compaq laptop. I know it is not a duplex printer. But my old HP 940C allows me to select a "Print on both sides" button on the printer properties advanced page. Doe