Move row values to columns

Hi all,
i have a a table that looks like this:
ID NAME ADDR
01 SAM USA
02 JIM USA
03 BEN USA
03 BEN ENG
04 TIM ENG
05 MEG USA
05 MEG JAP
05 MEG ENG
i need it so that names BEN and MEG do not have separate records for every ADDR they have. every ADDR should be in a column within the same record. the maximum ADDR is 3.
ID NAME ADDR1 ADDR2 ADDR3
01 SAM USA
02 JIM USA
03 BEN USA ENG
04 TIM ENG
05 MEG USA JAP ENG
can somebody help?
Thanks!

SQL> with t
  2  as
  3  (select '01' ID ,'SAM' NAME,'USA' ADDR from dual
  4  union all
  5  select'02','JIM','USA' from dual
  6  union all
  7  select'03','BEN','USA' from dual
  8  union all
  9  select'03','BEN','ENG' from dual
10  union all
11  select'04','TIM','ENG' from dual
12  union all
13  select'05','MEG','USA' from dual
14  union all
15  select'05','MEG','JAP' from dual
16  union all
17  select'05','MEG','ENG' from dual
18  )
19  select id,
20         name,
21         max(decode(rn,1,addr,null)) ADDR1,
22         max(decode(rn,2,addr,null)) ADDR2,
23         max(decode(rn,3,addr,null)) ADDR3
24  from
25      (select id,name,addr,row_number() over(partition by ID order by 1) rn
26       from t)
27  group by id,name
28  order by 1
29  /
ID NAM ADD ADD ADD
01 SAM USA
02 JIM USA
03 BEN USA ENG
04 TIM ENG
05 MEG USA JAP ENG
SQL>

Similar Messages

  • Row Values To Columns.

    Hi,
    I'm looking to cut row-values to columns and here is my data-set and my objective...
    delimiter ( for readability ) : "," ( comma )
    column1, column2, column3, column4
    10, name=john, age=30, state=ca, country=usa
    20, name=jane, age=25, null, null
    Output
    column1, column2, column3
    10, name, john
    10, age, 30
    10, state, ca
    10, country, usa
    20, name, jane
    20, age, 25
    Please advice.
    Thanks much.
    Edited by: shankariyer on Nov 2, 2008 11:17 AM
    Edited by: shankariyer on Nov 2, 2008 11:18 AM

    Here is one method with more dynamic approach - a little weired ;)
    satyaki>
    satyaki>select * from v$version;
    BANNER
    Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Prod
    PL/SQL Release 10.2.0.3.0 - Production
    CORE    10.2.0.3.0      Production
    TNS for 32-bit Windows: Version 10.2.0.3.0 - Production
    NLSRTL Version 10.2.0.3.0 - Production
    hello welcome
    Elapsed: 00:00:00.39
    satyaki>
    satyaki>
    satyaki>with pro_satyaki
      2  as
      3    (
      4       select 10 col_1, 'name=john, age=30, state=ca, country=usa' d_col from dual
      5       union all  
      6       select 20, 'name=jane, age=25, null, null' from dual 
      7    )
      8  select col_1, 
      9         trim(
    10               substr(
    11                       cast(tt.column_value.extract('//text()') as varchar2(100)),
    12                       1,
    13                       instr(cast(tt.column_value.extract('//text()') as varchar2(100)),'=')-1
    14                     )
    15             ) col_2,
    16         trim(
    17               substr(
    18                       cast(tt.column_value.extract('//text()') as varchar2(100)),
    19                       instr(cast(tt.column_value.extract('//text()') as varchar2(100)),'=')+1
    20                     )
    21             ) col_3
    22  from pro_satyaki,
    23       table(xmlsequence(xmltype('<x><x>' || replace(d_col,',','</x><x>') || '</x></x>').extract('//x/*'))) tt
    24  where trim(
    25              substr(
    26                      cast(tt.column_value.extract('//text()') as varchar2(100)),
    27                      instr(cast(tt.column_value.extract('//text()') as varchar2(100)),'=')+1
    28                    )
    29            ) <> 'null' ;
         COL_1 COL_2                                                                                                COL_3
            10 name                                                                                                 john
            10 age                                                                                                  30
            10 state                                                                                                ca
            10 country                                                                                              usa
            20 name                                                                                                 jane
            20 age                                                                                                  25
    6 rows selected.
    Elapsed: 00:00:00.27
    satyaki>Regards.
    Satyaki De.

  • Supplying row value as column name

    Hi all,
    I have two tables in which row value in one table is column name of other. How do i relate it to retreive the data...
    Table 1: control (contains 3 columns in it)
    table_name - parametername - parametervalue
    MI     - UNPROCESSED_FLAG -     N
    MI     - PROCESSED_FLAG - Y
    MI     - FROM_DATE     - 01-JAN-2008
    MI     - TO_DATE     - 31-DEC-2010
    EMP     - DEPTNO     - 30
    EMP     - JOB     - SALESMAN
    EMP     - FROM_DATE     - 01-JAN-1982
    EMP     - TO_DATE     - 31-DEC-1995
    Table 2: emp (contains the columns: empno,ename,deptno,job,hiredate)
    I want to display all details from emp table according to the parameter given in control table. I have already written a query using subquery
    select *
    from emp
    where
    deptno = (select parameter_value from job_control where parameter_name = 'DEPTNO')
    and
    job = (select parameter_value from job_control where parameter_name = 'JOB')
    and
    hiredate between (select parameter_value from job_control where parameter_name = 'FROM_DATE' and table_name = 'EMP') and (select parameter_value from job_control where parameter_name = 'TO_DATE' and table_name = 'EMP');
    But i want to write ot using joins. Plz help me out.....
    Thanks

    Hi,
    Welcome to the forum!
    Whenever you have a question, please post CREATE TABLE and INSERT statements for your sample data, so that the people who want to help you can re-create the problem and test their ideas. (There's no need to post commonly available tables. like those in the scott schema, but make it clear which such tables you're using.) Since this is your first post, I'll do it for you:
    CREATE TABLE     control_table
         table_name     VARCHAR2 (20)
    ,     parametername     VARCHAR2 (20)
    ,     parametervalue     VARCHAR2 (20)
    INSERT INTO control_table (table_name, parametername, parametervalue) VALUES ('EMP', 'DEPTNO',       '30');
    INSERT INTO control_table (table_name, parametername, parametervalue) VALUES ('EMP', 'JOB',       'SALESMAN');
    INSERT INTO control_table (table_name, parametername, parametervalue) VALUES ('EMP', 'FROM_DATE', '01-SEP-1981');
    INSERT INTO control_table (table_name, parametername, parametervalue) VALUES ('EMP', 'TO_DATE',       '31-DEC-1995');
    INSERT INTO control_table (table_name, parametername, parametervalue) VALUES ('MI',  'FROM_DATE', '01-JAN-2008');
    ;Also post the exact results you want from that sample data. The query below produces these results from the control_table above and the standard scott.emp table:
    EMPNO ENAME      JOB         MGR HIREDATE    SAL  COMM DEPTNO
    7654 MARTIN     SALESMAN   7698 28-SEP-81  1250  1400     30
    7844 TURNER     SALESMAN   7698 08-SEP-81  1500     0     30Always say which version of Oracle you're using. The query below works in Oracle 9.1 and up.
    One thing you can do is pivot the appropriate parameters into a one-row result set, and treat it as a table, like this:
    WITH     got_params     AS
         SELECT  TO_NUMBER (MIN (CASE WHEN parametername = 'DEPTNO'    THEN parametervalue END))               AS deptno
         ,             MIN (CASE WHEN parametername = 'JOB'       THEN parametervalue END)               AS job
         ,     TO_DATE   (MIN (CASE WHEN parametername = 'FROM_DATE' THEN parametervalue END), 'DD-MON-YYYY')     AS fromdate
         ,     TO_DATE   (MIN (CASE WHEN parametername = 'TO_DATE'   THEN parametervalue END), 'DD-MON-YYYY')     AS todate
         FROM     control_table
         WHERE     table_name     = 'EMP'
    SELECT  e.*
    FROM     emp         e
    JOIN     got_params  p  ON   e.deptno     = p.deptno
                     AND  e.job     = p.job
                     AND  e.hiredate     BETWEEN  p.fromdate
                                        AND      p.todate
    ;This assumes that the combination (table_name, parametername) is unique in the control_table.

  • Convert row values to columns

    
    I have a SQL statement which outputs a two column table with a ProjectName and a MemberFullValue, both text types values:
    SELECT proj.ProjectName, lt.MemberFullValue
    FROM dbo.MSP_EpmProject_UserView AS proj
    LEFT JOIN [dbo].[MSPCFPRJ_IT Pillar(s)_AssociationView] AS itpillar
    ON proj.ProjectUID = itpillar.EntityUID
    LEFT JOIN dbo.MSP_EpmLookupTable AS lt
    ON itpillar.LookupMemberUID = lt.MemberUID
    Both columns can contain duplicate values and both contain text.
    When there are duplicate values for 'ProjectName' I want to convert the corresponding 'MemberFullValue' values to columns. I have looked at a lot of different solutions to questions already posted, but I am not a SQL genius so I cannot get any of them to work.
    Can someone help me out? Thanks.
    

    Sounds like this to me
    SELECT ProjectName,
    [1] AS Value1,
    [2] AS value2,
    [3] AS Value3,
    [4] AS Value4,
    [5] AS Value5,
    [6] AS Value6
    FROM
    SELECT ROW_NUMBER() OVER (PARTITION BY proj.ProjectName ORDER BY proj.ProjectName) AS Seq,
    proj.ProjectName, lt.MemberFullValue
    FROM dbo.MSP_EpmProject_UserView AS proj
    LEFT JOIN [dbo].[MSPCFPRJ_IT Pillar(s)_AssociationView] AS itpillar
    ON proj.ProjectUID = itpillar.EntityUID
    LEFT JOIN dbo.MSP_EpmLookupTable AS lt
    ON itpillar.LookupMemberUID = lt.MemberUID
    )t
    PIVOT (MAX(MemberFullValue) FOR Seq IN ([1],[2],[3],[4],[5],[6]))p
    to make it dynamic you can use this
    http://beyondrelational.com/modules/2/blogs/70/posts/10840/dynamic-pivot-in-sql-server-2005.aspx
    If this is not what you're after, post some sample data and explain the required output
    Please Mark This As Answer if it solved your issue
    Please Mark This As Helpful if it helps to solve your issue
    Visakh
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • Please help - Joining three tables and get row values into Column. Please help!

    Hi,
    There is a SourceTable1 (Employee) with Columns like EmployeeID,Name,DOB.
    There is a sourcetable2 (EmployeeCode) with columns like EmployeeID,Code,Order.
    There is a source table 3  #EmployeeRegioncode  and its columns are (EmployeeID , RegionCode , [Order] 
    The target table 'EmployeeDetails' has the following details. EmployeeID,Name,DOB,Code1,Code2,Code3,Code4,regioncode1
    regioncode2 ,regioncode3 ,regioncode4 
    The requirement is , the value of the target table columns the Code1,code2,code3 ,code4,code5 values should
    be column 'Code' from Sourcetable2 where its 'Order' column is accordingly. ie) Code1 value should be the 'Code' value where [Order] column =1, and Code2 value should be the 'Code' value where [Order] =2, and so on.
    Same is the case for Source table 3- 'Region code' column also for the columns  regioncode1
    regioncode2 ,regioncode3 ,regioncode4 
    Here is the DDL and Sample date for your ref.
    IF OBJECT_ID('TEMPDB..#Employee') IS NOT NULL DROP TABLE #Employee;
    IF OBJECT_ID('TEMPDB..#EmployeeCode') IS NOT NULL DROP TABLE #EmployeeCode;
    IF OBJECT_ID('TEMPDB..#EmployeeDetails') IS NOT NULL DROP TABLE #EmployeeDetails;
    ---Source1
    CREATE table #Employee 
    (EmployeeID int, Empname varchar(20), DOB date )
    insert into #Employee VALUES (1000,'Sachin','1975-12-12') 
    insert into #Employee VALUES (1001,'Sara','1996-12-10') 
    insert into #Employee  VALUES (1002,'Arjun','2000-12-12')
    ---Source2
    CREATE table #EmployeeCode 
    (EmployeeID int, Code varchar(10), [Order] int)
    insert into #EmployeeCode VALUES (1000,'AA',1) 
    insert into #EmployeeCode VALUES (1000,'BB',2)   
    insert into #EmployeeCode  VALUES (1000,'CC',3)  
    insert into #EmployeeCode VALUES  (1001,'AAA',1)  
    insert into #EmployeeCode  VALUES  (1001,'BBB',2)  
    insert into #EmployeeCode  VALUES  (1001,'CCC',3)  
    insert into #EmployeeCode  VALUES  (1001,'DDD',4)  
    insert into #EmployeeCode  VALUES  (1002,'AAAA',1)  
    insert into #EmployeeCode  VALUES  (1002,'BBBB',2)  
    insert into #EmployeeCode  VALUES  (1002,'CCCC',3)  
    insert into #EmployeeCode  VALUES  (1002,'DDDD',4)  
    insert into #EmployeeCode  VALUES  (1002,'EEEE',5)  
    ---Source tbl 3
    CREATE table #EmployeeRegioncode 
    (EmployeeID int, RegionCode varchar(10), [Order] int)
    insert into #EmployeeRegioncode VALUES (1000,'xx',1) 
    insert into #EmployeeRegioncode VALUES (1000,'yy',2)   
    insert into #EmployeeRegioncode  VALUES (1000,'zz',3)  
    insert into #EmployeeRegioncode VALUES  (1001,'xx',1)  
    insert into #EmployeeRegioncode  VALUES  (1001,'yy',2)  
    insert into #EmployeeRegioncode  VALUES  (1001,'zz',3)  
    insert into #EmployeeRegioncode  VALUES  (1001,'xy',4)  
    insert into #EmployeeRegioncode  VALUES  (1002,'qq',1)  
    insert into #EmployeeRegioncode  VALUES  (1002,'rr',2)  
    insert into #EmployeeRegioncode  VALUES  (1002,'ss',3)  
    ---Target
    Create table #EmployeeDetails
    (EmployeeID int, Code1 varchar(10), Code2 varchar(10),Code3 varchar(10),Code4 varchar(10),Code5 varchar(10) , regioncode1 varchar(10),
    regioncode2 varchar(10),regioncode3 varchar(10),regioncode4 varchar(10))
    insert into #EmployeeDetails  VALUES (1000,'AA','BB','CC','','','xx','yy','zz','')  
    insert into #EmployeeDetails  VALUES (1001,'AAA','BBB','CCC','DDD','','xx','yy','zz','xy')  
    insert into #EmployeeDetails VALUES (1002,'AAAA','BBBB','CCCC','DDDD','EEEE','qq','rr','ss','')  
    SELECT * FROM  #Employee
    SELECT * FROM  #EmployeeCode
    SELECT * FROM  #EmployeeRegioncode
    SELECT * FROM  #EmployeeDetails
    Can you please help me to get the desired /targetoutput?  I have sql server 2008.
    Your help is greatly appreciated.

    select a.EmployeeID,b.code1,b.code2,b.code3,b.code4,b.code5,c.Reg1,c.Reg2,c.Reg3,c.Reg4 from
    #Employee a
    left outer join
    (select EmployeeID,max(case when [Order] =1 then Code else '' end) code1,
    max(case when [Order] =2 then Code else '' end)code2,
    max(case when [Order] =3 then Code else '' end)code3,
    max(case when [Order] =4 then Code else '' end)code4,
    max(case when [Order] =5 then Code else '' end)code5 from #EmployeeCode group by EmployeeID) b
    on a.EmployeeID=b.EmployeeID
    left outer join
    (select EmployeeID,max(case when [Order] =1 then RegionCode else '' end) Reg1,
    max(case when [Order] =2 then RegionCode else '' end)Reg2,
    max(case when [Order] =3 then RegionCode else '' end)Reg3,
    max(case when [Order] =4 then RegionCode else '' end)Reg4 from #EmployeeRegioncode group by EmployeeID) c
    on a.EmployeeID=c.EmployeeID
    Thanks
    Saravana Kumar C

  • Row values into column....

    Hi Experts,
    Can i add column values into a single cell. Like my requirement is i want to add values of Name column in a single cell of some other table. For example if Table A contains A, B, C D names then in second table i want all these name in one cell as ABCD. I'm not able to find solution. please help me. i'm working on ODI. Any help or clue.
    Regards
    -Kirti

    Hi,
    2 suggestions:
    1) If you have a constant number of columns you could put, at an interface, so much "instances" of the datastore as the number of columns, create the join and put the necessary filter at each "instance". The mapping will be the concatenation of the column from each instance
    or
    2) Create a procedure where you have the select column_to_be_concatenated at Source TAB and an update of that at Target TAB (if necessary you can define a dynamic PL/SQL to deal with insert update!)
    Does it help you?

  • How to convert some row values in columns

    Hello guys,
    I'm using Oracle 10g in a windows platform, I have the following data:
    with test as
    select '000-ME-001' tag_number, 'Capacity 150' tag_details1, '000-TS-M-226' tag_details2 from dual union all
    select '000-ME-001' tag_number, 'Capacity 250' tag_details1, '000-TS-M-227' tag_details2 from dual union all
    select '000-ME-001' tag_number, 'Capacity 350' tag_details1, '000-TS-M-228' tag_details2 from dual union all
    select '000-ME-002' tag_number, 'Capacity 150' tag_details1, '000-TS-M-226' tag_details2 from dual union all
    select '000-ME-002' tag_number, 'Capacity 250' tag_details1, '000-TS-M-227' tag_details2 from dual union all
    select '000-ME-002' tag_number, 'Capacity 350' tag_details1, '000-TS-M-228' tag_details2 from dual union all
    select '000-ME-003' tag_number, 'Capacity 150' tag_details1, '000-TS-M-226' tag_details2 from dual union all
    select '000-ME-003' tag_number, 'Capacity 250' tag_details1, '000-TS-M-227' tag_details2 from dual union all
    select '000-ME-003' tag_number, 'Capacity 350' tag_details1, '' tag_details2 from dual
    )How can I covert the values of tag_details1 as column name to achieve this result:
    tag_number     Capacity 150     Capacity 250     Capacity 350
    000-ME-001     000-TS-M-226     000-TS-M-227     000-TS-M-228
    000-ME-002     000-TS-M-226     000-TS-M-227     000-TS-M-228
    000-ME-003     000-TS-M-226     000-TS-M-227Hope you can help me, best regards.

    select tag_number
         , max (decode (tag_details1, 'Capacity 150', tag_details2))
         , max (decode (tag_details1, 'Capacity 250', tag_details2))
         , max (decode (tag_details1, 'Capacity 350', tag_details2))
      from test
    group by tag_numberas in
    SQL> with test as
      2  (
      3  select '000-ME-001' tag_number, 'Capacity 150' tag_details1, '000-TS-M-226' tag_details2 from dual union all
      4  select '000-ME-001' tag_number, 'Capacity 250' tag_details1, '000-TS-M-227' tag_details2 from dual union all
      5  select '000-ME-001' tag_number, 'Capacity 350' tag_details1, '000-TS-M-228' tag_details2 from dual union all
      6  select '000-ME-002' tag_number, 'Capacity 150' tag_details1, '000-TS-M-226' tag_details2 from dual union all
      7  select '000-ME-002' tag_number, 'Capacity 250' tag_details1, '000-TS-M-227' tag_details2 from dual union all
      8  select '000-ME-002' tag_number, 'Capacity 350' tag_details1, '000-TS-M-228' tag_details2 from dual union all
      9  select '000-ME-003' tag_number, 'Capacity 150' tag_details1, '000-TS-M-226' tag_details2 from dual union all
    10  select '000-ME-003' tag_number, 'Capacity 250' tag_details1, '000-TS-M-227' tag_details2 from dual union all
    11  select '000-ME-003' tag_number, 'Capacity 350' tag_details1, '' tag_details2 from dual
    12  )
    13  select tag_number
    14       , max (decode (tag_details1, 'Capacity 150', tag_details2))
    15       , max (decode (tag_details1, 'Capacity 250', tag_details2))
    16       , max (decode (tag_details1, 'Capacity 350', tag_details2))
    17    from test
    18   group by tag_number
    19  /
    TAG_NUMBER MAX(DECODE(T MAX(DECODE(T MAX(DECODE(T
    000-ME-002 000-TS-M-226 000-TS-M-227 000-TS-M-228
    000-ME-001 000-TS-M-226 000-TS-M-227 000-TS-M-228
    000-ME-003 000-TS-M-226 000-TS-M-227Edited by: Alex Nuijten on Jun 3, 2009 4:03 PM

  • How to convert a row value in CSV file to column value

    Hi
    We have one requirement where we have to show the row value to column level value
    for Example:
    Source file will be in below format
    Component Name :101
    **Batch #     **100% Mod     200% Mod      300% Mod      400% Mod     Tensile     Elongation     Thickness*
    8584-17     498     1211     1986     2601     3133 523     0.088
    Output Format has to be:
    **Batch #     **100% Mod     200% Mod      300% Mod      400% Mod     Tensile     Elongation     Thickness Component name*
    8584-17     498     1211     1986     2601     3133 523     0.088 101
    How can we achieve this using shell/Perl script

    .

  • How to get the value of column from previous row to current row?

    Hi All,
    I am facing a critical problem in SQL query (for reporting purpose (COGNOS)). please reply to my query.
    REQUIREMENT: i want to retrive value of a column (this is not a table column, this will be calculated based expression) from previous row to current row.
    EXAMPLE:
    TABLE NAME: i have to join multiple tables. so, i am not mentioning table names here.
    DISPLAY COLUMNS in the report: item, loc, sku, beginval (not table column), endval (not table column, this will calculated based on some expressions), etc. Here, first time the value of BEGINVAL will be taken from some x column name of x table. ENDVAL will calculated based on the expression. For the next row onwards, BEGINVAL will become the value of ENDVAL and the value of ENDVAL will be calculated based on the expression and this expression uses the value of BEGINVAL.
    my report will look like below.
    ITEM LOC SKU BEGINVAL ENDVAL
    1 HYD 1-HYD 10 10+1+2 (13)
    2 HYD 2-HYD 13 13+1+2 (16)
    3 SEC 3-SEC 16 16+1+2 (19)
    4 SEC 4-SEC 19 19+1+2 (22)
    etc....
    in the above output, BEGINVAL and ENDVAL columns are not part of any table. they are alias column names.if you observe intially BEGINVAL will be assigned to some value, but from subsequent rows, BEGINVAL will become the ENDVAL of previous row.
    Please help me on how to write this query?

    Hi, please find the detail description of the problom.
    DDL (table scripts)
    ITEM
    CREATE TABLE ITEM
    ITEM VARCHAR2(50 CHAR) NOT NULL,
    DESCR VARCHAR2(50 CHAR) DEFAULT ' ' NOT NULL,
    UOM           VARCHAR2(50 CHAR)
    SKU
    CREATE TABLE SKU
    ITEM VARCHAR2(50 CHAR) NOT NULL,
    LOC VARCHAR2(50 CHAR) NOT NULL,
    OH float
    SKUPROJSTATIC
    CREATE TABLE SKUPROJSTATIC
    ITEM VARCHAR2(50 CHAR) NOT NULL,
    LOC VARCHAR2(50 CHAR) NOT NULL,
    STARTDATE DATE
    VehicleLoad
    CREATE TABLE VEHICLELOAD
    LOADID VARCHAR2(50 CHAR) NOT NULL,
    DESCR VARCHAR2(50 CHAR) DEFAULT ' ' NOT NULL,
    SHIPDATE DATE DEFAULT TO_DATE('01/01/1970','MM/DD/YYYY') NOT NULL,
    ARRIVDATE      DATE
    VEHICLELOADLINE
    CREATE TABLE VEHICLELOADLINE
    LOADID VARCHAR2(50 CHAR) NOT NULL,
    ITEM VARCHAR2(50 CHAR) NOT NULL,
    QTY float(126)
    DML scripts
    I can't provide the the DML scripts, because its very huge data.
    Main QUERY is below.
    below is the query which i have to write and execute.
    select
    i.item,
    i.descr,
    i.unitsperpallet,
    sp.loc,
    sp.startdate,
    'Crucial_IND',
    LAG (EndBal,1,0) OVER (ORDER BY STARTDATE) BeginBal,
    SP.FCSTCUSTORDERS CustOrders,
    SP.COMMITINTRANSOUT,
    SP.RECARRIV,
    SP.TOTINTRANSIN,
    (BeginBal - sp.FCSTCUSTORDERS - sp.COMMITINTRANSOUT + sp.TOTINTRANSIN ) EndBal,
    'CuttingQty',
    VLL.QTY,
    vl.source,
    vl.arrivdate,
    vl.shipdate,
    vl.loadid,
    s.oh
    from item i, skuprojstatic sp, sku s, VehicleLoad vl, VehicleLoadLine vll
    where sp.item = i.item
    and s.item=i.item
    and sp.item =s.item (+)
    and sp.loc = s.loc (+)
    and vll.item = s.item
    and vll.loadid = vl.loadid
    and to_char(sp.startdate ,'mm/dd/yyyy') = to_char(vl.arrivdate,'mm/dd/yyyy')
    and sp.loc = vl.dest (+)
    order by sp.startdate
    problem description: in the above query, BeginBal and EndBal is what i am looking for. when i execute this query, oracle throwing an error saying that alias names can't be used as expressions. For the first row, the BeginBal should be the value sku.OH and for the subsequent rows, this value will be the previous row value of EndBal.

  • Concatenate multiple row values into single column value

    Hello,
    Can anyone please refresh my memory on how to concatenate multiple row values into a single column value.
    In the following query, I will get multiple denial reasons per application and I would rather return all denial reasons on one line.
    SELECT a.application_id, a.membership_number,
    r.reason_text AS denial_reason,
    a.appl_receipt_date AS application_receipt_date,
    a.plan_request_1 AS application_plan_code,
    a.adjudication_date AS application_denial_date
    FROM application a, PLAN p, application_reason ar, reason r
    WHERE a.plan_request_1 = p.plan_cd
    AND a.application_id = ar.application_id
    AND ar.reason_id = r.reason_id
    AND a.adjudication_cd = 'D'
    AND a.appl_receipt_date BETWEEN '01-jan-2006' AND '31-dec-2006'
    AND p.plan_type_id = 12 and a.application_id = :appId
    ORDER BY application_id
    Any help is greatly appreciated.
    Thanks,
    -Christine

    found the following
    SELECT deptno,
           LTRIM(MAX(SYS_CONNECT_BY_PATH(ename,','))
           KEEP (DENSE_RANK LAST ORDER BY curr),',') AS employees
    FROM   (SELECT deptno,
                   ename,
                   ROW_NUMBER() OVER (PARTITION BY deptno ORDER BY ename) AS curr,
                   ROW_NUMBER() OVER (PARTITION BY deptno ORDER BY ename) -1 AS prev
            FROM   emp)
    GROUP BY deptno
    CONNECT BY prev = PRIOR curr AND deptno = PRIOR deptno
    START WITH curr = 1;
        DEPTNO EMPLOYEES
            10 CLARK,KING,MILLER
            20 ADAMS,FORD,JONES,SCOTT,SMITH
            30 ALLEN,BLAKE,JAMES,MARTIN,TURNER,WARD
    3 rows selected.at http://www.oracle-base.com/articles/10g/StringAggregationTechniques.php

  • How to get rows values in a column only ?

    How to get all returned values in rows in a column.
    e.g., a query gives output as :
    123
    234
    233
    12121
    all in different rows. But i want the result like this:
    123,234,233,12121.All in a single row and a single column .
    How is this possible ?

    prakash wrote:
    hi ,
    Use the following example
    CREATE or  replace  FUNCTION fn_return_row
    RETURN VARCHAR2
    IS
    v_row   VARCHAR2 (32767);
    BEGIN
    FOR curr_row IN (SELECT ename
    FROM emp11)
    LOOP
    v_row := v_row ||','|| curr_row.ename;
    END LOOP;
    RETURN v_row;
    EXCEPTION
    WHEN OTHERS
    THEN
    RETURN NULL;
    END fn_return_row;
    select fn_return_row from dual ;Thanks,
    P PrakashThere's no need to use PL/SQL when SQL provides adequate functionality to do it.
    The title of the thread is misleading as turning rows into columns is called pivoting, but the description of the issue wanting to join all the rows together into a single column, is actually called string aggregation.
    As already demonstrated it can be done several ways.
    1. with XML functionality
    2. using the SYS_CONNECT_BY_PATH method
    and if you have 11gR2, there's...
    3. the new LISTAGG analytical function.
    There is also an undocumented WMSYS.WM_CONCAT function, though this isn't as flexible as other methods in that you can't control the order of the aggregated data so easily, and using such undocumented functions in production code is dangerous, as the functionality could change in future versions of Oracle, as well as it's use making your code such that Oracle will not provide support if the code with issue is using it.

  • How to get fourthly row (row4) first column value (col1) in matrix

    Hi to all,
    In FMS, how to get fourthly row (row4) first column value (col1) in matrix in document.
    select $[$38.1.4]
    But it display the first row
    Please give me hint.
    Thank you

    Hi Eric,
    FMS may only apply to current row.  There is no way to get any other fixed row.
    Thanks,
    Gordon

  • Hide row values for certain column in GRR2

    Hi Experts,
    Looking for some help in report painter. I need to hide row values for certain columns in report painter. The requirement is I have 5 columns in the report, the 5 th column is the sum of col 1 to 4 and in my row i have a formula setup to sum of values for each column, what i would like to do is for column 1 thru 4 i didnt want to display the total values in row total but i wanted to dispaly value for column 5 in row total. I have been trying my best with putting formula, but couldnt succeed.
    Could somebody let me know is there an way to get this addressed.
    Thanks in advance
    Best Regards,
    gj

    How was it achieved ? Did you use sections for the columns for which rows needed to be hidden?
    I have a smiliar issue of hiding certain rows for few columns.

  • How to merge three columns values to single row values in sql server 2008

    Hi Frds.....
    I have three quantity in my table.
    Quantity1,quantity2,quantity3
    this three quantity have different values
    ex:
    quantity1 = 1000,quantity2=2000,quantity3=3000
    the three column combine 2 display in single row values. this values display in one by one.
    ex: quantity
         1000
         2000
         3000

    You will need to use the UNPIVOT operator:
    DECLARE @example TABLE
    Id int NOT NULL IDENTITY(1,1),
    Quantity1 int,
    Quantity2 int,
    Quantity3 int
    INSERT INTO @example VALUES (1000, 2000, 3000), (4000, 5000, 6000);
    SELECT * FROM @example;
    SELECT Id, Quantity, QuantityType
    FROM @example
    UNPIVOT
    Quantity FOR QuantityType IN (Quantity1, Quantity2, Quantity3)
    ) AS u;
    Output:
    (2 row(s) affected)
    Id Quantity1 Quantity2 Quantity3
    1 1000 2000 3000
    2 4000 5000 6000
    (2 row(s) affected)
    Id Quantity QuantityType
    1 1000 Quantity1
    1 2000 Quantity2
    1 3000 Quantity3
    2 4000 Quantity1
    2 5000 Quantity2
    2 6000 Quantity3
    (6 row(s) affected)

  • Populate columns with row values in Sql Server Reporting Services

    I have got a dataset with 2 columns named Row and Title. There are 8 rows in this dataset and I want to display those 8 titles within columns in a table. So I create a table with 8 columns and set each column's expression to
    =LookUp(Fields!Row.Value,1,Fields!Title.Value,"Titles")
    =LookUp(Fields!Row.Value,2,Fields!Title.Value,"Titles")
    =LookUp(Fields!Row.Value,3,Fields!Title.Value,"Titles")
    However only the first column displays a title. The other 7 display nothing. Is my expression wrong?

    Hi,
    Is the row datatype non-numeric?  Maybe the lookup is failing for that reason.  You coulr try adding a conversion to the field:
    =LookUp(cint(Fields!Row.Value),1,Fields!Title.Value,"Titles")
    Could you, perhaps, instead use a tablix table and put the Title column on the row group?  That would pivot the data the way that you want it.
    Mark

Maybe you are looking for

  • "Could not read from source" exporting on Mac with CS4

    I'm using Premiere CS4 on a MacBook Pro, trying to export a film and getting the  "could not read from source" message.  I did not have CS3, and I'm not on a pc, so the Windows KB articles and posts don't apply.  I've read all the posts I can find on

  • IMac 24": crash/unbootable after airport express 2007-001 update

    My iMac 24" (2.33GHz, Nvidia 7600GS) crashed when applying the update listed at http://www.apple.com/support/downloads/airportextremeupdate2007001.html Video became corrupted, and underneath the garbled sceen appeared the grey "restart your computer"

  • Authorization for ABAP Query

    Hello all, Can I benefit a little from your experience with SAP Query(ABAP) and Adhoc Query(ABAP)? My customer want to use both SAP Query and Adhoc Query. And they want to separate for SAP Query as preset report program and Adhoc Query as general-pur

  • Syncing Photos with Adobe Photoshop Elements 7.0

    I have an iphone and a 160GB iPod classic. I have been syncing my photos from Adobe Photoshop Elements 6 to these devices. However, I recently upgraded to version 7 of Elements. I kept version 6 on my computer as well in case I needed to go back to i

  • How to change how many cores to use in after effects cs4

    so i raced my laptop vs my desktop desktop:intel core 2 quad 2.33 ghz  4 gigs of ram laptop: intel core 2 duo 1.83 ghz 4 gigs of ram and my desktop beat it by a little bit kinda sad then i went to edit>preferences>memory&multiprocessing then i clicke