How to Generate Dynamic Columns from SQL

Hi Friends,
I want to create a data fromat like This
Showroom / date    01-01-09        02-01-09     03-01-09     04-01-09      05-01-09     06-01-09     07-01-09   
S1                           20                      10              09            90             90                  10            100
S2                           10                       1                1              2               6                    2             10
S3                            5                        7                 9             1               2                    3             12This Data is Just like Matriz Reports....................................
Here i Want to Generate Date column value Dynamically.....................is it possible through SQL
the values are Sales value for each showroom for diffrent date value
all sale,showroom and Date Column are in one Table......................
It should Generate date Dynamically depending on User VAlues./..............
Thanks in Advance

something to play with (not tested as I don't have database access)
declare
/* assuming table showroom_sales has columns a_showroom,a_date,a_sale */
  the_sql varchar2(32000) := 'select a_showroom';
  day_from date := to_date('20090101','yyyymmdd');
  day_till date := to_date('20090107','yyyymmdd');
begin
  for d in (select a_date from showroom_sales where a_date between day_from and day_till)
  loop
    the_sql := the_sql ||
               ',max(decode(a_date,to_date('''||to_char(d.a_date,'yyyymmdd')||''',''yyyymmdd''),a_sale,null)) "'||to_char(d.a_date,'dd-mm-rr')||'"'
  end loop;
  the_sql := the_sql || ' from showroom_sales group by a_showroom order by a_showroom ';
  dbms_output.put_line(the_sql);  /* to verify if query is correct or not */
end;the code above should generate something like (provided all those dates appear in your showroom_sales table)
select a_showroom,
       max(decode(a_date,to_date('20090101','yyyymmdd'),a_sale,null)) "01-01-09",
       max(decode(a_date,to_date('20090102','yyyymmdd'),a_sale,null)) "02-01-09",
       max(decode(a_date,to_date('20090103','yyyymmdd'),a_sale,null)) "03-01-09",
       max(decode(a_date,to_date('20090104','yyyymmdd'),a_sale,null)) "04-01-09",
       max(decode(a_date,to_date('20090105','yyyymmdd'),a_sale,null)) "05-01-09",
       max(decode(a_date,to_date('20090106','yyyymmdd'),a_sale,null)) "06-01-09",
       max(decode(a_date,to_date('20090107','yyyymmdd'),a_sale,null)) "07-01-09"
  from showroom_sales
group by a_showroom
order by a_showroom to be executed to get the result as required
Regards
Etbin

Similar Messages

  • How to generate XML file from SQL file !

    I am new to XML publisher. I known one way to generate XML file is register one report file in concurrent manager.
    But I want to generate XML file from sql file.
    Could someone show me how to code in sql file, how to register is in concurrent manager.
    Thanks !

    Hi
    Phew ... not sure we have the space here. So I can point you in the right direction:
    1. XML data generation - there are two packages in the db you can use with a plsql procedure, XMLGEN and SQL XML. You can also use java APIs too. Try checking the db documentation and search for the above methods.
    2. Registering the report - the system administrators guide will provide this info. Hooking the program up with XMLP is covered here - http://www.oracle.com/technology/products/applications/publishing/resource/CM%20Whitepaper5.0.pdf
    Regards, Tim

  • How to read BLOB column from a table in SQL or PL/SQL

    I have table which is having one BLOB data type column . Ihave inserted few rows in that table . Now i want to see wheather BLOB column has been inserted properly or not . How to read that column through SQL or PL/SQL.
    Can anyone help me to do this.

    You can only manipulate LOBs in PL/SQL because you have to use the DBMS_LOB package.
    Check out the Oracle Developer's Guide

  • How to generate dynamic param file

    Hi, Can anyone please tell me how to generate dynamic parameter file from a table. Table has following structure: create table parameter_temp{Folder_name ,Workflow_name,session_name,parameter_name,parameter value} This table stores all the parameters for all the workflows. How can I generate parameter file for specific session or workflow. Thanks,

    Hi All, I have a scenario to implement.Need urgent help. I have relational source which has below fields. ID,Account,AccountType,Balance1,1001,GL,46567.901,1002,SL,56889.971,1003,Equity,45543.9081,1004,GL,89.541,1005,SL,-56889.971,1006,Equity,-45543.9081,1007,SL,-42777.45  Here my first requiremnt is to check if the balance value for entire file is 0 and if balance amount for each AccoutType is 0 , if both condtionn satifies the flow will go , else load will fail. I tried in below approach. SQ >> Expression >> Aggregator  In aggregaor i have first calculated sum(balance) for entire file by group by on ID column in an aggregator , and keep actual data in expression transformation. Then i took an expression to connect actual data with the sum(balance) , since i need to perform further calculation.I tried connecting expression and aggregator , but it is not allowing me to connect the posrts. And if i am using a joiner , then wrong data is loading to target. It is joining each result of aggregator with actual ports in expression.   I am not sure how to handle this scenario, so that we can just calculate sum of entire file and sum on basis of account type , is both sum are 0 then load the target , else fail.

  • How to delete a column from the table control in module pool?

    Hi,
      can any one please tell How to delete a column from the table control in module pool?
    thanks in advance
    warm regards
    HareeshKumar N

    hi hareesh,
    I think it is better to hide it.
    How to hide: You can check this link
    Dynamic Hide column in table control

  • Generating dynamic column in planning layout

    Hi Guys,
    I am new to BPS.. My task is user inputs calendar year thru variable, based on the year it has generate dynamic columns as month of the year entered by the user.
    Dnt know i am right or wrong based on the sdn threads. i think i have to create user input variable, and create a FM to read the user input value. Upto to this i can understand, after reading the user input how to calculate the months and generate 12 columns dynamically for each month...
    Kindly help me in this scenario..
    Edited by: kevin peterson on Jun 6, 2008 5:23 AM

    Hi,
    I hope you are using calendar year/month and calendar year characteristics. Create an user input variable for calendar year,
    create one exit variable for calendar year month.
    Inside this exit, read the value of the user input variable, append the year with all 12 months, so u get 12values for this exit variable.
    Now keep calendar year in header, restricted by user input variable, create one data column dynamic for calendar year month restricted by this exit variable. This will generate 12columns dynamically.
    Bindu

  • Generating dynamic columns for a report

    Hi all,
          Can anybody pls. tell me how to output dynamic columns in a report. my req. is that i've to generate so many columns as there are no. of unique(a particular field value) rows in my internal table. for e.g say suppose i've 5 rows in my internal table which has 2 fields, one short text & it's corresponding value. so now my report output shud have 5 columns with the short text as the column heading & the their corresponding values below each column heading. i heard it can be done thru field-symbols. can anyone pls. guide me.

    Hi Sushma,
    This piece of code might be useful.
    The following sections will help you to understand the steps required to define a Dynamic ALV.
    Following symbol signifies:
    Þ                    Important
    Main Steps Required
    The following are the main steps that are to be performed for defining a dynamic Alv
    1.       Defining a field catalog
    2.       Defining the dynamic table
    3.       Filling data into the table
    4.       Displaying ALV list
    Defining a field catalog
    The purpose of defining a field catalog first in case of Dynamic ALV is somewhat different than in case of normal ALV. In case of Dynamic ALV the field catalog is used to define the final internal table that will hold the data, and would be used to display the final output.
    Þ It is very important to remember that the field catalog table be refreshed first, else it might give an error.
    For example:
    DATA: T_FIELDCAT TYPE LVC_T_FCAT,
    L_FIELDCAT TYPE LVC_S_FCAT.
       Refresh T_FIELDCAT.
      CLEAR L_FIELDCAT.
      L_FIELDCAT-FIELDNAME = 'LIFNR'.
      L_FIELDCAT-INTTYPE = ''.
      L_FIELDCAT-OUTPUTLEN  = 10.
      L_FIELDCAT-COLTEXT  = TEXT-002.
      APPEND L_FIELDCAT TO T_FIELDCAT.
    Defining the dynamic table.
    This table will hold the final data that needs to be displayed. To declare the table the following things need to be done.
    Declare a field symbol
    Displaying Alv List
    This is done in the same way as we do for normal Alv. Call function “REUSE_ALV_GRID_DISPLAY” and pass the field catalog table in the export parameters and the dynamic table in Tables.
    Reward Points if it is helpful.
    Reagrds,
    Kiran I

  • How to add Two Columns in SQL

    How to add Two Columns in SQL
    For Example
    Jan Feb
    215 NULL
    How to add these two values in SQL

    Anything + NULL is NULL.
    Check this:
    SQL> SELECT 1 + NULL from dual;
        1+NULL
    SQL> You have to do this:
    SQL> with t as (SELECT 235 JAN, NULL FEB FROM dual)
      2  SELECT NVL(JAN,0) + NVL(FEB,0) FROM t;
    NVL(JAN,0)+NVL(FEB,0)
                      235
    SQL>

  • Desc doesn't show datetime columns from SQl Server

    Hi Everyone,
    I have working db link to sql server using hsodbc:
    Oracle 10.2 on AIX using freetds odbc driver version 0.82.
    I can access tables on sql server but oracle sees only varchars and numerics columns in a table.
    Is there a way to select datetime columns from sql server using hsodbc?

    when hsodbc does not show a certain data type it is commonly related to the fact that HSODBC doesn't support the related ODBC data type.
    In general you have a data type in your SQL Server which is mapped to an ODBC data type by the ODBC driver. HSODBC then maps the ODBC data type to an Oracle equivalent and when the ODBC data type isn't supported by HSODBC it just drops it from the select list.
    So for a root cause analysis an ODBC trace is required to determine the mapping of the FreeTDS ODBC driver.
    With this info we can then compare the mapping documented in the HSODBC manual and if the ODBC data type isn't listed as a supported data type you then need to cast the data type on the source side to a different data type (for example varchar/char).
    So please post the ODBC trace and I'll have a look.
    - Klaus
    Edited by: kgronau on Apr 2, 2013 12:50 PM
    BTW, here the link to the HSODBC docu:
    http://docs.oracle.com/cd/B19306_01/server.102/b14232.pdf
    Oracle® Database
    Heterogeneous Connectivity Administrator's Guide
    10g Release 2 (10.2)
    B14232-01
    B.1 Mapping ANSI Data Types to Oracle Data Types Through an ODBC
    Interface

  • How to insert select columns from one internal table to another

    Hi,
    How to insert select columns from one internal table to another based on condition as we do from a standart table to internal table.
    regards,
    Sriram

    Hi,
    If your question is for copying data from 1 int table to other ;
    we can use
    APPEND LINES OF it_1 TO it_2.
    or if they have different columns then:
    loop at it_1 into wa_it1.
    move wa_it1-data to wa_it2-d1.
    apped wa_it2 to it_2.
    clear wa_it2.
    endloop.
    thnxz

  • How can I select columns from a table EMP, using Select statement?.

    Hi Friends,
    How can I select columns from a table EMP?.
    I want to select columns of EMP table, using select statement.
    Please reply me urgently.
    Shahzad

    Something like this:
    scott@DBA> select empno,ename,job from emp;
         EMPNO ENAME      JOB
          7369 SMITH      CLERK
          7499 ALLEN      SALESMAN
          7521 WARD       SALESMAN
          7566 JONES      MANAGER
          7654 MARTIN     SALESMAN
          7698 BLAKE      MANAGER
          7782 CLARK      MANAGER
          7788 SCOTT      ANALYST
          7839 KING       PRESIDENT
          7844 TURNER     SALESMAN
          7876 ADAMS      CLERK
          7900 JAMES      CLERK
          7902 FORD       ANALYST
          7934 MILLER     CLERK
    14 rows selected.Check the documentation:
    http://download-east.oracle.com/docs/cd/B19306_01/server.102/b14200/statements_10002.htm#sthref9697
    Message was edited by:
    Delfino Nunez

  • How to separate perticular column from multidimensionl array

    dear all,
    i am just reading CAN bus message, problem is that it is accomodated in a 11X7 array which includes frame time stamp, ID, byte length etc but i am interested in CAN data. can anybody tell me how to separate that column from all. i want to read a column of 5 with all rows. how it is possible.

    Hello Sanjay,
    If your requirement is simply to obtain a single column from a 11x7 array, I would suggest you should do the following:
    1. Use Transpose 2D array to obtain a transposed array
    2. Use Index Array function to retrieve invidual row (which is actually the column of non-transposed array).
    Use index value of 4 (zero indexed), and the output would be a 1D array containing all elements of column 4 (zero indexed) of the original array.
    I hope this helps.
    Regards,
    Navjodh

  • How to access Oracle 8g from SQL Server 2005 SP3 EE 64 Bits ?

    Dear All,
    How to access Oralce 8g from SQL Server 2005 SP3 EE 64 Bits (liked server).
    Best regards,
    Miguel Gavinhos

    Hi!
    For the Oracle version is 8.1.6. what should I install, to access Oracle trought a linked server.
    Best regards
    Miguel Gavinhos

  • How to connect to db from sql navigator ?

    database active and working.
    login from web working normally.
    how to connect to db from sql navigator ?

    Remote connections generally need three bits of information, whether its an oracle, odbc, or some other type of client ...
    1. Where does the database "live" (hostname or IP address)
    2. What port is the database listener "listening" on for connections
    3. What is the database service name or $ORACLE_SID
    Default port is 1521, if its an XE install the service name is XE out-of-the-box (as set up by the installer and no DBA intervention.)

  • How to display dynamic column added by vo.addDynamicAttribute in jspx?

    Hi,
    I met problem when programmatically add cloumn and display it on screen. Here are my steps:
    0. define a ViewObject using xml. Define a transient column Addtion2. later will add a dynamic column Addtion3, but not defined here.
    1. Implement Application Module, adding a method init() and expose it to client.
    2. In init() method, get target VO and use vo.addDynamicAttribute("Addition3"). Then iterate it use row.setAttribute("Addition3", Math.random()). Add init() to page binding and invoke it.( it's invoked )
    3. In jspx, use dynamic table. But Addition3 never shows up.
    This is my last question: Re: How to display dynamic column added by vo.addDynamicAttribute in jspx? People say I should use dynamic table.
    please have a look at my code:
    Application Module: when it runs, it will print 6 coulmns. vo.getAttributeCount() is <font color="red">6</font>.
    <pre>
    public void init() {
    ViewObject vo = this.getCountryView1();
    if (vo.getAttributeIndexOf("Addition3") == -1) {
    vo.addDynamicAttribute("Addition3");
    vo.executeQuery();
    for (AttributeDef deft : vo.getAttributeDefs()) {
    System.out.println(deft.getColumnName() + ": " + deft.getName());
    RowSetIterator it = vo.createRowSetIterator("i1");
    while (it.hasNext()) {
    Row r = it.next();
    r.setAttribute("Addition2", Math.random());
    r.setAttribute("Addition3", Math.random());
    it.closeRowSetIterator();
    for (AttributeDef deft : vo.getAttributeDefs()) {
    System.out.println(deft.getColumnName() + ": " + deft.getName());
    System.out.println(vo.getAttributeCount()); //vo.getAttributeCount() is 6
    </pre>
    jspx: when it runs, only 5 columns are shown. Column Addition2's values are set as expected. but Column Addition3 never shows up. And #{bindings.CountryView1.attributeCount} shows <font color="red">5</font>.
    <pre>
    <af:table rows="#{bindings.CountryView1.rangeSize}"
    fetchSize="#{bindings.CountryView1.rangeSize}"
    emptyText="#{bindings.CountryView1.viewable ? 'No data to display.' : 'Access Denied.'}"
    var="row" rowBandingInterval="0"
    value="#{bindings.CountryView1.collectionModel}"
    selectedRowKeys="#{bindings.CountryView1.collectionModel.selectedRow}"
    selectionListener="#{bindings.CountryView1.collectionModel.makeCurrent}"
    rowSelection="single" id="t1">
    <af:forEach items="#{bindings.CountryView1.attributeDefs}" var="def">
    <af:column headerText="#{def.name}"
    sortable="true" sortProperty="#{def.name}" id="c1">
    <af:outputText value="#{row[def.name]}" id="ot1"/>
    </af:column>
    </af:forEach>
    </af:table>
    <af:forEach items="#{bindings.CountryView1.attributeDefs}" var="def">
    <af:outputText value="#{def.name}" id="ot2"/>
    </af:forEach>
    <af:outputText value="#{bindings.CountryView1.attributeCount}" id="ot3"/>
    </pre>
    it's quite weird for me. The vo.getAttributeCount() is 6, but #{bindings.CountryView1.attributeCount} shows 5. And column Addtion3 never shows up.
    what's the matter? How can I show the dynamic added column Addtion3?
    Edited by: simon li on 2012-9-10 下午7:31
    Edited by: simon li on 2012-9-10 下午8:00

    Hi,
    Can you check the tree binding (CountryView1 - in the pagedef) and see it has the 5 attributes hardcoded in it. If yes, try removing everything and then run the page to see if it works fine.
    -Arun

Maybe you are looking for

  • Can I delete the Itunes update 10.6 and go back to 1.2?

    Can I delete the Itunes update 10.6 and go back to 1.2?

  • Create table as select (CTAS)statement is taking very long time.

    Hi All, One of my procedure run a create table as select statement every month. Usually it finishes in 20 mins. for 6172063 records and 1 hour in 13699067. But this time it is taking forever even for 38076 records. When I checked all it is doing is C

  • Database views are missing

    Post Author: dee7231 CA Forum: Data Connectivity and SQL We have an ODBC connection to an Oracle database.  There are 7 views that are created.  However when we try to pick the view from the table selection in crystal, we see the tables but not the v

  • How to change password of sys user connected as sysdba?

    How to change password of sys user connected as sysdba? I have connected with user name sys as sysdba in oracle 9i with password oracle. I want to change the password . I typed password and pressed entered. It asks me to type old password, then new p

  • Sd card videos won't play

    I'm trying to play videos in avi format but the iPad will not play it. Is there anyway I can play it without having to move to a different computer?