Dynamic alias name in query

Is it possible to use dynamic alias name in query for interactive report?
I have this SELECT and I would like to use the parameters used in alias request to build a dynamic crosstab report:
SELECT p.annee AS "Année", p.desc_rls AS "RLS",
SUM(CASE WHEN p.age BETWEEN :P2_AGE1 AND :P2_AGE2 THEN p.pop END) "0-4 ANS",
SUM(CASE WHEN p.age BETWEEN :P2_AGE3 AND :P2_AGE4 THEN p.pop END) "5-9 ANS",
SUM(CASE WHEN p.age BETWEEN :P2_AGE5 AND :P2_AGE6 THEN p.pop END) "10-14 ANS"
FROM pop_rls_isq_111 p
GROUP BY ROLLUP(p.annee, p.desc_rls);
Instead of coding "0-4 ANS" as alias, I would like for example use the parameters ":P2_AGE1 - :P2_AGE2 ANS".

Hi,
to make your column headings dynamic you can use the substitution syntax in the "Column Heading" property of your IR columns. For example:
&P2_AGE1. - &P2_AGE2. ANSHope that helps
Patrick
My blog: http://www.oracleapex.info/
New Check out the Oracle APEX Essentials!

Similar Messages

  • Dynamic schema name in query

    hi there,
    who knows how to cheat a little and add schema name dynamically in report query?
    curently trying PLSQL function body returning SQL
    ...from ' || '&P1_SCHEMA.' ||'.IM_INVOICES_V
    where...
    any bright thoughts?
    crazy Simon

    Hi,
    You could try something like this...
    CREATE OR REPLACE FORCE VIEW IM_INVOICES_V_VW AS
    SELECT 'SCHEMA_1'.the_schema,
           IM_INVOICES_V.*
    FROM   schema1.IM_INVOICES_V
    UNION ALL
    SELECT 'SCHEMA_2'.the_schema,
           IM_INVOICES_V.*
    FROM   schema2.IM_INVOICES_V;
    and then...
    SELECT *
    FROM   IM_INVOICES_V_VW
    WHERE  the_schema = :P1_SCHEMA
    AND ...Cheers
    Ben

  • SQL query alias names errors with dynamic lists

    Hullo,
    Problem:
    - Made a query form book database. Have authors in separate table with unique ID's referring to them on book table.
    - Query fetches author name in "Surname, Firstname initial.Secondfirstname initial" format, --> like "Bukowski, H.C" and giving that combo alias name in SQL like "AS 'author'"...
    - Dynamic list works fine at start, but when ordered from detail table back to the mainlisting, it does make an error with SQL stating "unknown column 'author' in where clause"
    That must be because the script looks for "author" column from the original table yeah, but how can I solve this? Any ideas? Does this mean that Alias names for columns are not possible or is there something i've missed?
    Any ideas, suggestions?
    Thanks,
    KimmoK

    Hi Kimmo,
    ADDT´s dynamic lists can handle alias columns fine to my experience, but I reckon that you most probably applied the "CONCAT(...) AS author" query modification after having generated the list, and the list´s internal WHERE clause seems to have no clue of this alias column.
    You can get an idea about using alias columns in Dynamic Lists in my tutorial "Dynamic Lists: exploring the Filter Conditions": http://www.guenter-schenk.com/tutorials/tutorial.php?id=6
    Can you please post the list´s code on your server as text file (e.g. code.txt) and provide a link to this file ?
    Cheers,
    Günter Schenk
    Adobe Community Expert, Dreamweaver

  • Get alias name from dynamic query

    Hi All,
    I would make a plsql function using dynamic query.
    And the function takes a whole sql query as a parameter.
    The main issue is that the function should get what alias or columns were queried.
    For example,
    FUNCTION_GET_QUERY_ALIAS('SELECT 1 AS col1, 2 AS col2 FROM DUAL')
    Inside the function, it should find the alias name COL1 and COL2.
    I'd appreciate for any help.

    I have modified print_table as function and made it to satisfy your needs.
    SQL> CREATE OR REPLACE TYPE my_column_object AS OBJECT(ruw_number integer, column_name VARCHAR2(1000), column_val VARCHAR2(1000))
      2  /
    Type created.
    SQL> CREATE OR REPLACE TYPE my_table_type AS TABLE OF my_column_object
      2  /
    Type created.
    SQL> CREATE OR REPLACE FUNCTION print_table( p_query in varchar2 ) RETURN my_table_type PIPELINED
      2  AS
      3      l_theCursor     INTEGER DEFAULT DBMS_SQL.OPEN_CURSOR;
      4      l_columnValue   VARCHAR2(4000);
      5      l_status        INTEGER;
      6      l_descTbl       DBMS_SQL.DESC_TAB;
      7      l_colCnt        NUMBER;
      8      l_rcount           INTEGER := 0;
      9  BEGIN
    10      DBMS_SQL.PARSE(  l_theCursor,  p_query, dbms_sql.native );
    11
    12      DBMS_SQL.DESCRIBE_COLUMNS( l_theCursor, l_colCnt, l_descTbl );
    13
    14      FOR i IN 1 .. l_colCnt
    15      LOOP
    16          DBMS_SQL.DEFINE_COLUMN(l_theCursor, i, l_columnValue, 4000);
    17      end loop;
    18
    19      l_status := DBMS_SQL.EXECUTE(l_theCursor);
    20
    21      WHILE ( DBMS_SQL.FETCH_ROWS(l_theCursor) > 0 )
    22      LOOP
    23             l_rcount := l_rcount + 1;
    24          FOR i IN 1 .. l_colCnt
    25          LOOP
    26              DBMS_SQL.COLUMN_VALUE( l_theCursor, i, l_columnValue );
    27
    28              PIPE ROW(my_column_object(l_rcount,l_descTbl(i).col_name,l_columnValue));
    29          END LOOP;
    30      END LOOP;
    31
    32     RETURN;
    33  end;
    34  /
    Function created.
    SQL> select * from table(print_table('select * from emp'))
      2  /
    RUW_NUMBER COLUMN_NAME          COLUMN_VAL
             1 EMPNO                7369
             1 ENAME                SMITH
             1 JOB                  CLERK
             1 MGR                  7902
             1 HIREDATE             17-DEC-80
             1 SAL                  800
             1 COMM
             1 DEPTNO               20
             1 DIV                  10
             2 EMPNO                7499
             2 ENAME                ALLEN
    RUW_NUMBER COLUMN_NAME          COLUMN_VAL
             2 JOB                  SALESMAN
             2 MGR                  7698
             2 HIREDATE             20-FEB-81
             2 SAL                  1600
             2 COMM                 300
             2 DEPTNO               30
             2 DIV                  10
             3 EMPNO                7521
             3 ENAME                WARD
             3 JOB                  SALESMAN
             3 MGR                  7698
    RUW_NUMBER COLUMN_NAME          COLUMN_VAL
             3 HIREDATE             22-FEB-81
             3 SAL                  1250
             3 COMM                 500
             3 DEPTNO               30
             3 DIV                  10
             4 EMPNO                7566
             4 ENAME                JONES
             4 JOB                  MANAGER
             4 MGR                  7839
             4 HIREDATE             02-APR-81
             4 SAL                  2975
    RUW_NUMBER COLUMN_NAME          COLUMN_VAL
             4 COMM
             4 DEPTNO               20
             4 DIV                  10
             5 EMPNO                7654
             5 ENAME                MARTIN
             5 JOB                  SALESMAN
             5 MGR                  7698
             5 HIREDATE             28-SEP-81
             5 SAL                  1250
             5 COMM                 1400
             5 DEPTNO               30
    RUW_NUMBER COLUMN_NAME          COLUMN_VAL
             5 DIV                  10
             6 EMPNO                7698
             6 ENAME                BLAKE
             6 JOB                  MANAGER
             6 MGR                  7839
             6 HIREDATE             01-MAY-81
             6 SAL                  2850
             6 COMM
             6 DEPTNO               30
             6 DIV                  10
             7 EMPNO                7782
    RUW_NUMBER COLUMN_NAME          COLUMN_VAL
             7 ENAME                CLARK
             7 JOB                  MANAGER
             7 MGR                  7839
             7 HIREDATE             09-JUN-81
             7 SAL                  2450
             7 COMM
             7 DEPTNO               10
             7 DIV                  10
             8 EMPNO                7788
             8 ENAME                SCOTT
             8 JOB                  ANALYST
    RUW_NUMBER COLUMN_NAME          COLUMN_VAL
             8 MGR                  7566
             8 HIREDATE             19-APR-87
             8 SAL                  3000
             8 COMM
             8 DEPTNO               20
             8 DIV                  10
             9 EMPNO                7839
             9 ENAME                KING
             9 JOB                  PRESIDENT
             9 MGR
             9 HIREDATE             17-NOV-81
    RUW_NUMBER COLUMN_NAME          COLUMN_VAL
             9 SAL                  5000
             9 COMM
             9 DEPTNO               10
             9 DIV                  10
            10 EMPNO                7844
            10 ENAME                TURNER
            10 JOB                  SALESMAN
            10 MGR                  7698
            10 HIREDATE             08-SEP-81
            10 SAL                  1500
            10 COMM                 0
    RUW_NUMBER COLUMN_NAME          COLUMN_VAL
            10 DEPTNO               30
            10 DIV                  10
            11 EMPNO                7876
            11 ENAME                ADAMS
            11 JOB                  CLERK
            11 MGR                  7788
            11 HIREDATE             23-MAY-87
            11 SAL                  1100
            11 COMM
            11 DEPTNO               20
            11 DIV                  10
    RUW_NUMBER COLUMN_NAME          COLUMN_VAL
            12 EMPNO                7900
            12 ENAME                JAMES
            12 JOB                  CLERK
            12 MGR                  7698
            12 HIREDATE             03-DEC-81
            12 SAL                  950
            12 COMM
            12 DEPTNO               30
            12 DIV                  10
            13 EMPNO                7902
            13 ENAME                FORD
    RUW_NUMBER COLUMN_NAME          COLUMN_VAL
            13 JOB                  ANALYST
            13 MGR                  7566
            13 HIREDATE             03-DEC-81
            13 SAL                  3000
            13 COMM
            13 DEPTNO               20
            13 DIV                  10
            14 EMPNO                7934
            14 ENAME                MILLER
            14 JOB                  CLERK
            14 MGR                  7782
    RUW_NUMBER COLUMN_NAME          COLUMN_VAL
            14 HIREDATE             23-JAN-82
            14 SAL                  1300
            14 COMM
            14 DEPTNO               10
            14 DIV                  10
    126 rows selected.
    SQL>Thanks,
    Karthick.
    Edited by: Karthick_Arp on Sep 23, 2008 12:11 AM

  • How to set dynamic table name in sql query?

    I want set dynamic table name by parameter in sql query,just like:
    select * from :tbname
    but run report is error,BI P report table name is invalidation.
    What can i do? Thanks!

    Hi,
    that's only possible inside a data template with a lexical parameter.
    Regards
    Rainer

  • SQL query - Alias name (value) as parameter to an Oracle function

    Hi,
    I have a sql query something like
    Select tbl1.valueA, tbl1.valueB, tbl2.valueX, MAX(CASE tbl2.valueY = 'XX' THEN tbl2.valueZ END) AS "ValueZ header", Function(tbl1.valueB, tbl2.valueX, "valueZ header")
    FROM table1 tbl1
    JOIN table2 tbl2 ON tbl1.id = tbl2.tbl1id
    WHERE ...
    my problem is that I need the value from MAX statement as parameter to the function and I have tried to use the alias name (valueZ header) but this is not working. I guess because of some syntax error. Can I use alias name as parameter into the function at all - if - how should I do this?

    Hi,
    user8819407 wrote:
    Hi,
    I have a sql query something like
    Select tbl1.valueA, tbl1.valueB, tbl2.valueX, MAX(CASE tbl2.valueY = 'XX' THEN tbl2.valueZ END) AS "ValueZ header", Function(tbl1.valueB, tbl2.valueX, "valueZ header")
    FROM table1 tbl1
    JOIN table2 tbl2 ON tbl1.id = tbl2.tbl1id
    WHERE ...
    my problem is that I need the value from MAX statement as parameter to the function and I have tried to use the alias name (valueZ header) but this is not working. I guess because of some syntax error. Can I use alias name as parameter into the function at all - if - how should I do this?You can use a column alias in the ORDER BY clause of the same query where it was defined, but that's the only place where you can use it in that query.
    You could repeat the entire MAX (CASE ...) expression as the 3rd argumnet to your function, or you could compute it once in a sub-query, then reference the column alias as often as you like in the super-query, like this:
    WITH     got_valuez_header     AS
         Select  tbl1.valueA
         ,     tbl1.valueB
         ,     tbl2.valueX
         ,     MAX ( CASE
                            WEHN  tbl2.valueY = 'XX'     -- Don't forget the keyword WHEN
                      THEN      tbl2.valueZ
                    END
                  )          AS "ValueZ header"
         FROM         table1     tbl1
         JOIN         table2     tbl2     ON     tbl1.id     = tbl2.tbl1id
         WHERE          ...
         GROUP BY     ...
    Select  tbl1.valueA
    ,     tbl1.valueB
    ,     tbl2.valueX
    ,     "ValueZ header"
    ,     Function_x ( tbl1.valueB     -- FUNCTION is not a good name for a function
                 , tbl2.valueX
                 , "ValueZ header"     -- Case-sensitive
    FROM    got_valuez_header
    ;

  • Dynamic table name, how to query?

    Hi!
    There is a table name that is decided dynamically. the name is:
    someNameYYY where YYY denotes the client number.
    I get the client number by sy-mandt and concatenate it with someNameYYY to lc_table_name but then comes the problem:
    I cannot do
    SELECT *
    FROM  lc_table_name
    because I get compiler error "lc_table_name" is not defined in ABAP dictionary.
    How do I query a table with the name decided dynamically?
    regards
    Baran

    You can have do something like this :
    REPORT ZTABLE_DOWNLOAD .
    tables :
    dd02l,    "SAP Tables
    dd03l,    "Table fields
    dd04t.    "R/3 DD: Data element texts
    constants : c_activation_status(1)  value 'A',
               c_tabclass(6) type c    value 'INTTAB',
               c_language(2) type c    value 'EN'.
    type-pools : slis.
    selection-screen begin of block b1 with frame title text-003.
    *parameters :p_mandt like t001-mandt obligatory default '560'.
    parameters :p_table like dd03l-tabname obligatory.
    selection-screen end of block b1.
    data:
    table_desc(70) type c,
    table_field like dd03l-fieldname,
    total_rows type i,
    t_rows(20) type c.
    field-symbols:
    <fs_line> type any,
    <fs_field> type any.
    at selection-screen.
    *Check for the existence of the table
    select single * from dd02l where tabname  = p_table
                                and   as4local = c_activation_status.
    if sy-subrc ne 0.
    *Table is not active in dictionary
       message e999(zs) with 'Table is not active in dictionary'.
    elseif dd02l-tabclass = c_tabclass.
    *It is a structure not a table
       message e999(zs) with 'This is a structure not a table'.
    endif.
    start-of-selection.
    perform table_data_display.
    end-of-selection.
    form table_data_display.
    data:
    l_long_type type i,
    lx_struct   type ref to data,
    lt_table    type ref to data,
    lcl_sdescr  type ref to cl_abap_structdescr,
    lx_lvc_cat  type lvc_s_fcat,
    lt_lvc_cat  type lvc_t_fcat,         "Field catalog
    lx_fieldcat type slis_fieldcat_alv,
    lt_fieldcat type slis_t_fieldcat_alv,
    lx_layout   type slis_layout_alv,
    lt_sort     type slis_t_sortinfo_alv, "Sort table
    ls_sort     type slis_sortinfo_alv.
    field-symbols :
    <fieldcat>    type slis_fieldcat_alv,
    <lt_table>    type table,
    <fs>          type any,
    <components>  type abap_compdescr.
    *Dynamic creation of a structure
    create data lx_struct type (p_table).
    assign lx_struct->* to <fs>.
    *Get the field structure
    lcl_sdescr ?= cl_abap_typedescr=>describe_by_data( <fs> ).
    loop at lcl_sdescr->components assigning <components>.
    *Do not display field "MANDT"
       IF sy-tabix = 1 AND <components>-name = 'MANDT'.
         CONTINUE. "next loop
       ENDIF.
    *Build fieldcatalog
       lx_lvc_cat-fieldname = <components>-name.
       lx_lvc_cat-ref_table = p_table.
       append lx_lvc_cat to lt_lvc_cat.
       lx_fieldcat-fieldname   = <components>-name.
       lx_fieldcat-ref_tabname = p_table.
       append lx_fieldcat to lt_fieldcat.
    endloop.
    *Create an internal table
    call method cl_alv_table_create=>create_dynamic_table
    exporting it_fieldcatalog = lt_lvc_cat
    importing ep_table        = lt_table.
    assign lt_table->* to <lt_table>.
    *Read the data
        select * from (p_table)
       into corresponding fields of table <lt_table>
       order by primary key.
      loop at <lt_table> assigning <fs_line>.
      assign component 'MANDT' of
             structure <fs_line> to <fs_field>.
          <fs_field> = p_mandt.
      endloop.
    if <lt_table>[] is initial.
    *No table enties are existing
       message e003(zdynamictable) with p_table.
       exit.
    else.
       describe table <lt_table>[] lines total_rows.
       t_rows = total_rows.
       shift t_rows left deleting leading space.
    endif.
    *Specify the layout
    lx_layout-zebra = 'X'.
    lx_layout-colwidth_optimize = 'X'.
    *Display the ALV List
    select single ddtext into table_desc from dd02t
    where tabname eq p_table and ddlanguage eq c_language.
    check not table_desc is initial.
    concatenate  'Entries from table:'
    p_table '(' table_desc ')' '-:' t_rows 'Entries Found' into
    table_desc
    separated by space.
    *Start - Download the data to excel sheet by validating the file path.
    data:
    *lv_filename type string,
    lv_fname_validate like rlgrap-filename.
    *CONCATENATE 'C:\ZTABLE_DWN\' P_TABLE '.Xls' INTO LV_FILENAME.
    *CONCATENATE '
    Pc-p31061\Harman\Tasks\ZTABLE_DWN\' P_TABLE '.xls' INTO
    CONCATENATE 'C:\ZTABLE_DWN\' P_TABLE '.xls' INTO
    LV_FNAME_VALIDATE.
    call function 'WS_FILE_DELETE'
    exporting
       file          = lv_fname_validate
    IMPORTING
      RETURN        =
    CALL FUNCTION 'WS_DOWNLOAD'
    EXPORTING
      BIN_FILESIZE                  = ' '
      CODEPAGE                      = ' '
      FILENAME                      =  LV_FNAME_VALIDATE
      FILETYPE                      = 'DAT'
    IMPORTING
      FILELENGTH                    =
    TABLES
       DATA_TAB                      = <lt_table>.
    *call function 'GUI_DOWNLOAD'
    exporting
      BIN_FILESIZE                  =
       filename                      = lv_fname_validate
      filetype                      = 'ASC'
      write_field_separator           =  'X'
    IMPORTING
      FILELENGTH                    =
    tables
       data_tab                      = <lt_table>.
    End of Download.
    call function 'REUSE_ALV_GRID_DISPLAY'
      exporting
        i_background_id                   = 'ALV_BACKGROUND'
        i_grid_title                      = table_desc
        is_layout                         = lx_layout
        it_fieldcat                       = lt_fieldcat
       tables
         t_outtab                          = <lt_table>
      exceptions
        program_error                     = 1
        others                            = 2
    if sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    endif.
    clear table_desc.
    endform.                    " table_data_display

  • Dynamic table name in native sql query

    Can i pass a dynamic table name in this query ---
                EXEC SQL PERFORMING APPEND_MTO.
                  SELECT          
                               LTOG_QUANTITY_TYPE,
                               FCONO,
                              WBSELEMENT,
                             PROJECT
                  INTO   :IMTO
                  FROM  RWORKS.MTO_ISO_V2
                  WHERE LTOD_DATE > TO_DATE(:MAXD,'YYYYMMDDHH24MISS')
                ENDEXEC.
    How can i pass this table name RWORKS.MTO_ISO_V2  dynamically in the query
    Edited by: Madhukar Shetty on Nov 26, 2009 2:40 PM

    Can i pass a dynamic table name in this query ---
                EXEC SQL PERFORMING APPEND_MTO.
                  SELECT          
                               LTOG_QUANTITY_TYPE,
                               FCONO,
                              WBSELEMENT,
                             PROJECT
                  INTO   :IMTO
                  FROM  RWORKS.MTO_ISO_V2
                  WHERE LTOD_DATE > TO_DATE(:MAXD,'YYYYMMDDHH24MISS')
                ENDEXEC.
    How can i pass this table name RWORKS.MTO_ISO_V2  dynamically in the query
    Edited by: Madhukar Shetty on Nov 26, 2009 2:40 PM

  • Dynamic change in the query name based on user input

    Hi Gurus,
    In a scenario, country appears as a user input variable.When the user specifies his country, the same query displays <b>Business trends</b>' data pertaining to his own country and rest of the world(international) in two tables.The reports are developed using Web application designer.
    Can the name(description) of the query be changed  so that the user input value for country gets dynamically reflected in the query name like <b>Business trends:Selected country vs International</b>?
    Regards,
    Balaji

    Hi Bala,
      ya this can be done by text variables. create a text variable( replacement path on the country infoobject) by going to the query properties on the description.
    if the user enters country value then it will be displaed on the description of the query .
    assign points if useful .
    regards
    santosh

  • Can I use dynamic alias to name a column?

    I guys. I just want to know if it is possible to assign dynamic names to a column. for instance:
    SQL> select sysdate+1 from dual;
    SYSDATE+1
    09-JUL-08the column name is SYSDATE+1. can I do something like:
    SQL> select 1 as (select sysdate from dual) from dual;(this throws error)
    The reason for this requirement is that I need to assign a column name according to a value that comes from a parameter. So, instead of returning something like:
    SQL> select sysdate, sysdate+1 from dual;
    SYSDATE   SYSDATE+1
    08-JUL-08 09-JUL-08I need to find a way to return something like:
    SQL> select sysdate as <<dynamic column name based on parameter that has been passed in>>, sysdate+1 AS <<dynamic column name based on parameter that has been passed in>> from dual;Obviously I can use something like:
    select sysdate as "08-JUL-08", sysdate+1 AS "09-JUL-08" from dual;But in this case I'm hard coding it. I need this alias to be dynamic.
    Any way to do it?

    Why? Column names are a "programming thing" - not a "display thing".
    When you render the columns, you can decide what and how to display them. It does not make any sense to attempt to do this dynamically.
    Why not?
    Sharable SQL.
    Everytime you create a SQL and dynamically change the column aliases, you create a brand new unique SQL - even if the rest of the SELECT is exactly the same. This means you are stuffing the shared pool full of non-sharable SQL.
    This is bad for performance (lots of hard parsing). It is bad for the shared pool (memory fragmentation).

  • How to shows result as Alias name.

    Dear All,
    I am having following query and output, in that inside query showing one record check another query, that result i want to show as Alias, Can we show result as alias ?
              select SPL.speciality_description,Emp.FIRSTNAME,DT.full_date                                   
              ,max(decode(diagnosis_description,                                   
              (SELECT DIAGNOSIS_DESCRIPTION                                   
              FROM (SELECT row_number() OVER (ORDER BY DIAGNOSIS_DESCRIPTION DESC) r,                                   
              DG.DIAGNOSIS_DESCRIPTION                                   
              FROM A_PERFORMANCEDOCTORWISE PD                                   
              INNER JOIN D_DATE DT ON DT.DATE_ID = PD.DATEID                                   
              INNER JOIN D_DIAGNOSIS DG ON DG.DIAGNOSISID = PD.DIAGNOSISID                                   
         WHERE DT.FULL_DATE between (select TO_CHAR(sysdate-15,'DD/MON/YYYY') from dual)                                         
         and (select TO_CHAR(sysdate,'DD/MON/YYYY') from dual) and ROWNUM < 6                                         
              ) WHERE r=1),patientcount)) as First                                   
              ,max(decode(diagnosis_description,                                   
              (SELECT DIAGNOSIS_DESCRIPTION FROM (                                   
              SELECT row_number() OVER (ORDER BY DIAGNOSIS_DESCRIPTION DESC) r,                                   
              DG.DIAGNOSIS_DESCRIPTION                                   
              FROM A_PERFORMANCEDOCTORWISE PD                                   
              INNER JOIN D_DATE DT ON DT.DATE_ID = PD.DATEID                                   
              INNER JOIN D_DIAGNOSIS DG ON DG.DIAGNOSISID = PD.DIAGNOSISID                                   
         WHERE DT.FULL_DATE between (select TO_CHAR(sysdate-15,'DD/MON/YYYY') from dual)                                         
         and (select TO_CHAR(sysdate,'DD/MON/YYYY') from dual) and ROWNUM < 6                                         
              ) WHERE r=2),patientcount)) as Second                                   
              ,max(decode(diagnosis_description,                                   
              (SELECT DIAGNOSIS_DESCRIPTION FROM (                                   
              SELECT row_number() OVER (ORDER BY DIAGNOSIS_DESCRIPTION DESC) r,                                   
              DG.DIAGNOSIS_DESCRIPTION                                   
              FROM A_PERFORMANCEDOCTORWISE PD                                   
              INNER JOIN D_DATE DT ON DT.DATE_ID = PD.DATEID                                   
              INNER JOIN D_DIAGNOSIS DG ON DG.DIAGNOSISID = PD.DIAGNOSISID                                   
              WHERE DT.FULL_DATE between (select TO_CHAR(sysdate-15,'DD/MON/YYYY') from dual)                                    
         and (select TO_CHAR(sysdate,'DD/MON/YYYY') from dual) and ROWNUM < 6                                         
              ) WHERE r=3),patientcount)) as Third                                   
              ,max(decode(diagnosis_description,                                   
              (SELECT DIAGNOSIS_DESCRIPTION FROM (                                   
              SELECT row_number() OVER (ORDER BY DIAGNOSIS_DESCRIPTION DESC) r,                                   
              DG.DIAGNOSIS_DESCRIPTION                                   
              FROM A_PERFORMANCEDOCTORWISE PD                                   
              INNER JOIN D_DATE DT ON DT.DATE_ID = PD.DATEID                                   
              INNER JOIN D_DIAGNOSIS DG ON DG.DIAGNOSISID = PD.DIAGNOSISID                                   
              WHERE DT.FULL_DATE between (select TO_CHAR(sysdate-15,'DD/MON/YYYY') from dual)                                    
         and (select TO_CHAR(sysdate,'DD/MON/YYYY') from dual) and ROWNUM < 6                                         
              ) WHERE r=4),patientcount)) as Forth                                   
              ,max(decode(diagnosis_description,                                   
              (SELECT DIAGNOSIS_DESCRIPTION FROM (                                   
              SELECT row_number() OVER (ORDER BY DIAGNOSIS_DESCRIPTION DESC) r,                                   
              DG.DIAGNOSIS_DESCRIPTION                                   
              FROM A_PERFORMANCEDOCTORWISE PD                                   
              INNER JOIN D_DATE DT ON DT.DATE_ID = PD.DATEID                                   
              INNER JOIN D_DIAGNOSIS DG ON DG.DIAGNOSISID = PD.DIAGNOSISID                                   
              WHERE DT.FULL_DATE between (select TO_CHAR(sysdate-15,'DD/MON/YYYY') from dual)                                    
         and (select TO_CHAR(sysdate,'DD/MON/YYYY') from dual) and ROWNUM < 6                                         
              ) WHERE r=5),patientcount)) as Fifth
              FROM A_PERFORMANCEDOCTORWISE PD                                   
              INNER JOIN D_SPECIALITY SPL ON SPL.SPECIALITYID = PD.SPECIALITYID                                   
              INNER JOIN D_EMPLOYEEMASTER EMP ON EMP.EMPID = PD.DOCTORID                                   
              INNER JOIN D_DATE DT ON DT.DATE_ID = PD.DATEID                                   
              INNER JOIN D_DIAGNOSIS DG ON DG.DIAGNOSISID = PD.DIAGNOSISID                                   
              WHERE DT.FULL_DATE between (select TO_CHAR(sysdate-15,'DD/MON/YYYY') from dual)                                    
              and (select TO_CHAR(sysdate,'DD/MON/YYYY') from dual)                                    
              group by SPL.speciality_description, Emp.FIRSTNAME, DT.full_date                                   
              order by SPL.speciality_description,Emp.FIRSTNAME,DT.full_date                                   
    Output:
    REGISTRATION     Dr.POOJA     19-JUL-10 12:00 AM     56     74     99     32     96
    REGISTRATION     Dr.POOJA     21-JUL-10 12:00 AM     93     74     45     43     69
    REGISTRATION     Dr.POOJA     22-JUL-10 12:00 AM     34     34     76     66     24
    REGISTRATION     Dr.POOJA     24-JUL-10 12:00 AM     99     75     97     78     69
    REGISTRATION     Dr.POOJA     26-JUL-10 12:00 AM     54     34     76     66     24
    REGISTRATION     Dr.POOJA     28-JUL-10 12:00 AM     76     75     97     78     33
    REGISTRATION     Dr.POOJA     30-JUL-10 12:00 AM     54     23     34     65     23
    Travel Clinic     Dr.PRAN     19-JUL-10 12:00 AM     56     74     99     32     96
    Travel Clinic     Dr.PRAN     21-JUL-10 12:00 AM     93     74     45     43     69
    Anothe Query :
    SELECT DIAGNOSIS_DESCRIPTION                                   
              FROM (SELECT row_number() OVER (ORDER BY DIAGNOSIS_DESCRIPTION DESC) r,                                   
              DG.DIAGNOSIS_DESCRIPTION                                   
              FROM A_PERFORMANCEDOCTORWISE PD                                   
              INNER JOIN D_DATE DT ON DT.DATE_ID = PD.DATEID                                   
              INNER JOIN D_DIAGNOSIS DG ON DG.DIAGNOSISID = PD.DIAGNOSISID                                   
         WHERE DT.FULL_DATE between (select TO_CHAR(sysdate-15,'DD/MON/YYYY') from dual)                                         
         and (select TO_CHAR(sysdate,'DD/MON/YYYY') from dual) and ROWNUM < 6                                         
              ) WHERE r=1
    Output:
    Neurocytoma
    I want to show this result as Alias name. Can anybody tell me how to do that ?
    Thanks and Regard's
    Harish Patil

    Hi,
    If I've understood the intention of your code correctly, you are trying to pivot the rows into columns and assign a "nice" header to the resulting columns.
    You cannot dynamically assign a column name to a pivoted row. You need to know beforehand what row you are pivoting so you can assign a column name to it. This isn't as difficult as it sounds, there are a number of ways you could know what row will become what column.
    Since I have no way to test using your code, I am posting an example for you that uses the EMP table that is part of the standard example databases shipped with Oracle.
    Also, notice that, the code I am presenting is enclosed between the tags (which you cannot see) [ code ] and [ / code ] which is why it appears nicely formatted. Your code would be much easier to read and folks would be much more likely to understand what you want and therefore help you if you take the time to format your code so it is comprehensible.
    See the basics of using tags to format your code at this page:
    http://wiki.oracle.com/page/Oracle+Discussion+Forums+FAQ
    Now the example that will help you get what you want:
    /* this query calculates the total salaries per deptno */
    SELECT job,
           deptno,
           sum(sal) sal
      FROM emp
    GROUP BY job, deptno;
    /* output is */
    JOB          SUM(SAL)
    CLERK            4150
    SALESMAN         5600
    PRESIDENT        5000
    MANAGER          8275
    ANALYST          6000
    /* this query pivots the above query (which is what you're trying to do) */
    SELECT *
      FROM (
            SELECT job,
                   deptno,
                   sum(sal) sal
              FROM emp
             GROUP BY job, deptno
      PIVOT (sum(sal) FOR deptno IN (10, 20, 30, 40));
    /* output is */
         CLERK   SALESMAN  PRESIDENT    MANAGER    ANALYST
          4150       5600       5000       8275       6000If you are not using 11g, there are ways of doing the above without using the PIVOT clause. There are lots of examples in this forum on how to pivot rows. Here is one that pretty much does manually what the PIVOT clause does:
    select max(case when job='CLERK'
                    then ename else null end) as clerks,
           max(case when job='ANALYST'
                    then ename else null end) as analysts,
           max(case when job='MANAGER'
                    then ename else null end) as mgrs,
           max(case when job='PRESIDENT'
                    then ename else null end) as prez,
           max(case when job='SALESMAN'
                    then ename else null end) as sales
    from (
    select job,
          ename,
          row_number()over(partition by job order by ename) rn
    from emp
          ) x
    group by rn
    /* outputs */
         CLERKS  ANALYSTS  MGRS   PREZ  SALES
         MILLER  FORD      CLARK  KING  TURNER
         JAMES   SCOTT     BLAKE        MARTIN
         ADAMS             JONES        WARD
         SMITH                          ALLENHTH,
    John.
    Edited by: 440bx - 11gR2 on Aug 2, 2010 9:28 AM - added missing verb "is" in sentence
    Edited by: 440bx - 11gR2 on Aug 2, 2010 9:32 AM - missing "s" in select.

  • How to change recordset bahaviour to accept dynamic column names in the where clause

    Hi
    im using php-mysql and i make a recordset and i want to make the column names in the where clause to be dynamic like
    "select id,name from mytable where $tablename-$myvar";
    but when i do this my i break the recordset and it disappear
    and when i use variables from advanced recordset it only dynamic for the value of the column not for the column name
    and when i write the column name to dynamic as above by hand it truns a red exclamation mark on the server behaviour panel
    so i think the only way is to change the recordset behaviour is it? if so How to make it accept dynamic column names?
    thanks in advance.

    As bregent has already explained to you, customizing the recordset code will result in Dreamweaver no longer recognizing the server behavior. This isn't a problem, but it does mean that you need to lay out your dynamic text with the Bindings panel before making any changes. Once you have changed the recordset code, the Bindings panel will no longer recognize the recordset fields.
    Using a variable to choose a column name is quite simple, but you need to take some security measures to ensure that the value passed through the query string isn't attempting SQL injection. An effective way of doing this is to create an array of acceptable column names, and check that the value matches.
    // create array of acceptable values
    $valid = array('column_name1', 'column_name2', 'column_name3');
    // if the query string contains an acceptable column name, use it
    if (isset($_GET['colname']) && in_array($_GET['colname'], $valid)) {
      $col = $GET['colname'];
    } else {
      // set a default value if the submitted one was invalid
      $col = 'column_name1'
    You can then use $col directly in the SQL query.

  • Saving result from sp_executesql into a variable and using dynamic column name - getting error "Error converting data type varchar to numeric"

    Im getting an error when running a procedure that includes this code.
    I need to select from a dynamic column name and save the result in a variable, but seem to be having trouble with the values being fed to sp_executesql
    DECLARE @retval AS DECIMAL(12,2)
    DECLARE @MonthVal VARCHAR(20), @SpreadKeyVal INT
    DECLARE @sqlcmd AS NVARCHAR(150)
    DECLARE @paramdef NVARCHAR(150)
    SET @MonthVal = 'Month' + CAST(@MonthNumber AS VARCHAR(2) );
    SET @SpreadKeyVal = @SpreadKey; --CAST(@SpreadKey AS VARCHAR(10) );
    SET @sqlcmd = N' SELECT @retvalout = @MonthVal FROM dbo.CourseSpread WHERE CourseSpreadId = @SpreadKeyVal';
    SET @paramdef = N'@MonthVal VARCHAR(20), @SpreadKeyVal INT, @retvalout DECIMAL(12,2) OUTPUT'
    --default
    SET @retval = 0.0;
    EXECUTE sys.sp_executesql @sqlcmd,@paramdef, @MonthVal = 'Month4',@SpreadKeyVal = 1, @retvalout = @retval OUTPUT;
    SELECT @retval
    DECLARE @return_value DECIMAL(12,2)
    EXEC @return_value = [dbo].[GetSpreadValueByMonthNumber]
    @SpreadKey = 1,
    @MonthNumber = 4
    SELECT 'Return Value' = @return_value
    Msg 8114, Level 16, State 5, Line 1
    Error converting data type varchar to numeric.

    Please follow basic Netiquette and post the DDL we need to answer this. Follow industry and ANSI/ISO standards in your data. You should follow ISO-11179 rules for naming data elements. You should follow ISO-8601 rules for displaying temporal data. We need
    to know the data types, keys and constraints on the table. Avoid dialect in favor of ANSI/ISO Standard SQL. And you need to read and download the PDF for: 
    https://www.simple-talk.com/books/sql-books/119-sql-code-smells/
    >> I need to select from a dynamic column name and save the result in a variable, but seem to be having trouble with the values being fed to sp_executesql <<
    This is so very, very wrong! A column is an attribute of an entity. The idea that you are so screwed up that you have no idea if you want
    the shoe size, the phone number or something else at run time of this entity. 
    In Software Engineering we have a principle called cohesion that says a model should do one and only one task, have one and only one entry point, and one and only one exit point. 
    Hey, on a scale from 1 to 10, what color is your favorite letter of the alphabet? Yes, your mindset is that level of sillyity and absurdity. 
    Do you know that SQL is a declarative language? This family of languages does not use local variables! 
    Now think about “month_val” and what it means. A month is a temporal unit of measurement, so this is as silly as saying “liter_val” in your code. Why did you use “sp_” on a procedure? It has special meaning in T-SQL.  
    Think about how silly this is: 
     SET @month_val = 'Month' + CAST(@month_nbr AS VARCHAR(2));
    We do not do display formatting in a query. This is a violation of at the tiered architecture principle. We have a presentation layer. But more than that, the INTERVAL temporal data type is a {year-month} and never just a month. This is fundamental. 
    We need to see the DDL so we can re-write this mess. Want to fix it or not?
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • Dynamic file name in case of .txt output files

    Hi all,
    I have a query related to dynamic file name scenario.
    In case of IDOC-XI-FILE sceanrio,
    <b>Is it possible to generate .txt file name based on Plant number like</b>
    <b>%<Plantname>%_%<BusinessDay>_filename.txt</b>
    <b>Note:I have implemneted this for .xml output files but I am not able to implement it for .txt output files .</b>
    PLEASE HELP ME .
    Regards
    Prabhat

    Hi Prabhat,
    I think, the normal Dynamic File Name generation should work fine in your case also. Even if you perform Content Conversion, you can use Variable Name Substiution to create your Destination file name as, the name of the file is determined first and only then is the content converison perfromed.
    for info on content conversion, I would suggest that you go through this thread and check my reply,
    Re: Dynamic  File Name for Receiver File Adapter
    Regards,
    Bhavesh

  • Passing Dynamic File Name to ODI nterface for processing to another system

    Hi,
    I need help regarding passing a Dynamically Name changing fixed length Flat File in ODI Interface. This interface is built for taking the Flat File as Input and process it to SQL Server by applying Data Mapping and transformations... The input Flat File Name is sequence generated for eg: OEORD1123.txt and next file will be OEORD1124.txt and it sits in Oracle Conc tier. How to pass the latest file name to ODI interface for processing
    Regards,
    Anil..

    Hi Guys...
    I would like to suggest a way.
    a) create a single interface with dynamic resouce name (a ODI variable) with a filter to the month column like:
    month_column = '#vCountMonth'
    b) in the refresh tab of a first variable (I named "vMonth"), use the following query: (varialbe should be alphanumeric, "not persistent")
    select to_char(to_date('#vCountMonth','MM'),'month') from dual
    c) create one more ODI variable (I named "vCountMonth"), alphanumeric, not persistent and at its refresh tab write:
    select lpad(to_char(#vCountMonth + 1), 2, '0') from dual
    d) now just create a package, drag and drop the objects in the following order:
    d.1) vCountMonth in set mode and set = 0 (zero)
    d.2) vCountMonth in refresh mode
    d.3) vMonth in refresh mode
    d.4) the interface
    d.5) vCountMonth in evaluate mode, evaluating "= 12"
    ==> if NO (KO, red line) link the KO line to d.2 step
    ==> a OK line is not necessary unless you have others steps after finish the evaluating
    Make any sense? That is a single loop to have the interface developed only one time.
    Please, remember to check each thread reply as Useful or Correct if they are useful to you...

Maybe you are looking for

  • Timecode in full screen view

    When I watch my videos in full screen I would like to know how much time has elapsed from the beginning of the video. The project view at the bottom of the screen does not show the playhead information so I have no idea where I am in the video. Does

  • Itunes app crash when downloading purchases in windows 7 64 bit

    Hi guys I have recently upgraded to windows 7 64 bit. My I-tunes works fine until I try to download a purchase. As soon at the download starts I get an app crash error and I tunes closes. I turned off my anti-virus and that did not help. Here is the

  • Print issue with Photoshop CS4 and Officejet 6500

    I have a Windows 7 Business 64 bits desktop computer. After  installing the Officejet Pro 6500 multifunctional drivers all was  working OK. Images were being printed nice and with the correct size  using Windows print option. After installing Adobe C

  • Not able to merge dimensions objects on webi report based on SAP query

    Hello We are using SAP BI 7.0 , BO XI 3.1 sp1 I have two queries in webi report. These two queries are based on the same universe. I am not able to merge dimensions from both queries as merge dimensions functionality is greyed. Two dimensions are of

  • PO Line Close API

    Hi, We have a legacy system that maintains PO related information.. whenever they close the PO lines..we need to update it in Oracle.. Can i close the PO lines using APIs... will it be possible using PO_CHANGE_API.update_po ? Regards Ramanathan