Need a Query that Returns both Column Name with Column Data

Hi,
Hope someone can assist quite quickly. I'm after a query that will return me both column name together with column data, i.e
Table: APP_INFO
COL1  - currently has the value of 10
COL2  - currently has the value of 'HELLO'
COL3  - currently has the value of 'QWERTY'
COL4  - currently has the value of 2000Query I'm after is to return the following result set: [actual column name, actual column data]
COL1,10
COL2,'HELLO',
COL3,'QWERTY'
COL4,2000
Any help would be much appreciated.
Thanks.
Tony.

Like this ?
SQL> select empno, ename, deptno from emp where deptno = 10;
     EMPNO ENAME          DEPTNO
      7782 CLARK              10
      7839 KING               10
      7934 MILLER             10
SQL> select decode(t.id,1,'EMPNO',2,'ENAME',3,'DEPTNO') COLNAME,
  2  decode(t.id,1,to_char(empno),2,ename,3,deptno)
  3  from (select emp.*, rownum rn from emp
  4  where deptno = 10) emp, (select rownum id from dict where rownum <=3) t
  5  order by emp.rn, t.id
  6  /
COLNAM DECODE(T.ID,1,TO_CHAR(EMPNO),2,ENAME,3,D
EMPNO  7782
ENAME  CLARK
DEPTNO 10
EMPNO  7839
ENAME  KING
DEPTNO 10
EMPNO  7934
ENAME  MILLER
DEPTNO 10
9 rows selected.Rgds.

Similar Messages

  • I need a query that returns the average amount of characters for a text colum in MS SQL.

    I need a query that returns the average amount of characters
    for a text colum in MS SQL.
    Could someone show me how?

    Sorted, i need the
    DATALENGTH
    function

  • Updating a table with a query that return multiple values

    Hi,
    I'm trying to update a table which contain these fields : ItemID, InventoryID, total amounts
    with a query that return these values itemId, inventoryid and total amounts for each items
    Mind you, not all the rows in the table need to be updated. only a few.
    This what i wrote but doesn't work since the query return multiple values so i can't assign it to journalAmounts.
    UPDATE [bmssa].[etshortagetemp]
    SET JournalAmounts = (SELECT sum(b.BomQty) FROM [bmssa].[Bom] b
    JOIN [bmssa].[SalesLine] sl ON sl.ItemBomId = b.BomId
    JOIN [bmssa].[SalesTable] st ON st.SalesId = sl.SalesId
    WHERE st.SalesType = 0 AND (st.SalesStatus IN (0,1,8,12,13)) AND st.DataAreaId = 'sdi'
    GROUP BY b.itemid, b.inventdimid)
    Any advise how to do this task?

    Remember that link to the documentation posted above that explains exactly how to do this. When you read it which part exactly were you having trouble with?

  • Need a query to list all table names

    I have more than 500 tables in my database.
    'insert_date' & 'update_date' columns are found in more than 100 tables with data type as date.
    I need a query to list all table names and 'insert_date' , 'update_date' column's content.
    Please Help
    Lee1212
    Message was edited by:
    LEE1212

    I have more than 500 tables in my database.
    'insert_date' & update_date column is found in more
    than 100 tables with data type as date.
    I need a query to list all table names and
    'insert_date' column's content.What do you mean by "column's content". A table can have many rows. Do you want to display all the distinct value for these columns?
    Below is the query to get the tables which has columns insert_Date and update_date
    select table_name
    from user_tab_columns
    where column_name ='INSERT_DATE'
    or column_name ='UPDATE_DATE'
    /You can write a PL/SQL block to retrive the distinct values of INSERT_DATE for these tables
    declare
    TYPE ref_cur IS REF CURSOR;
    insert_date_cur ref_cur;
    lv_insert_date DATE;
    cursor tables_list IS
    select table_name
    from user_tab_columns
    where column_name ='INSERT_DATE';
    begin
    for cur_tables in tables_list
    loop
      OPEN insert_date_cur for 'SELECT DISTINCT insert_date from '||cur_tables.table_name;
      DBMS_OUTPUT.PUT_LINE(cur_tables.table_name);
      DBMS_OUTPUT.PUT_LINE('--------------------------------');
      LOOP
      FETCH insert_date_cur into lv_insert_date;
      EXIT WHEN insert_date_cur%NOTFOUND;
      DBMS_OUTPUT.PUT_LINE(lv_insert_date);
      END LOOP;
    CLOSE insert_date_cur;
    end loop;
    end;I haven't tested this code. There might be some errors. Just posted something to start with for you.

  • I need a query that selects the amount of records for each day in a table.

    I need a query that selects the amount of records for each
    day in a table.
    Eg the result would be:
    date 1 14
    date 2 3
    etc
    Any ideas?

    sorted:
    SELECT count([commentID]),convert(varchar, dateAdded, 112)
    FROM COMMENTSgroup by convert(varchar, dateAdded,
    112)

  • Need Sql Query that Suppress the repeating rows.

    Hi Sir,
    I have below data set.
    DeptID  Sum(SAL) Avg(Sal)
      10      1300      1300
      10      2450      1300
      10      5000      1300
      20      800        800
      20      1100      800
      20      2975      800
      20      3000      800
      30      800        800
      30      1100      800
      30      2975      800
      40      3000      800
      40      4000      900
    I Need  SQL query that can remove the duplicate or suppress.Just like below data set.
    Output:
    DeptID  Sum(SAL) Avg(Sal)
      10      1300      1300
                2450      1300
                5000      1300
      20       800        800
                1100      800
                2975      800
                3000      800
                800        800
      30      1100      800
                2975      800
      40      3000      800
               4000      900
    Could you please help me on this..

    Your requiremnt is more of a reporting request which should not be handled in SQL. For example in SQL Plus you can use the BREAK command
    SQL> break on deptno
    SQL> select deptno, ename from emp order by deptno;
        DEPTNO ENAME
            10 KING
               CLARK
            20 JONES
               SCOTT
               SMITH
               ADAMS
            30 TURNER
               MARTIN
               WARD
               ALLEN
               BLAKE
    11 rows selected.
    SQL>
    But if you still wish to do it in SQL you can use ROW_NUMBER analytic function and achieve it like this
    select decode(rno, 1, deptno) deptno
         , ename
      from (
              select row_number() over(partition by deptno order by ename) rno
                   , deptno
                   , ename
                from emp

  • How to query / list table name with certain data type?

    Hi all spatials,
    Sorry for the dumb question. I need to make a query that list all table name that contain certain data type, eg. SDO_georaster. How to do this ?
    Many thanks in advance
    damon

    Skip it. I figured it : using USER_TAB_COLUMNS will definitely help.
    Cheers
    damon

  • When I open up an e-mail attachment a box pops up PRINT TO FILE below that line OUTPUT FILE NAME with an empty line for the file name vs. simply going to my default printer?

    when I open up an e-mail attachment a box pops up PRINT TO FILE below that line OUTPUT FILE NAME with an empty line for the file name vs. simply going to my default printer?

    Make sure that '''''Print to File''''' isn't selected in the native print dialog box ''(see screenshot below)'' middle-right, and make sure your Printer is selected at the top of that dialog box.
    ''I'm a little confused why an email attachment would need to go directly to the printer, but that's what you asked about.''

  • Same Input name with different data type cause the reflection exception

    I have a proxy contains couple RFCs. Two RFCs contain an argument named IN_COMPANY_CODE with data type of ZTRE_FX_BUKRSTable. Another RFC contains the same argument name of IN_COMPANY_CODE but hold different data type (String). All RFCs are in the same proxy. Complie and build the application with no issue.
    But when I ran the RFC, it generates the reflection exception below:
    Method SAPProxy1.Z_F_Tre_R_Pre_Trade_Fx can not be reflected. --> There was an error reflecting 'In_Company_Code'. > The XML element named 'IN_5fCOMPANY_--5fCODE' from namespace '' references distinct types System.String and MSTRFOREX.ZTRE_FX_BUKRSTable. Use XML attributes to specify another XML name or namespace for the element or types.
    I realize the conflict introduced by the same name with difference data type. But I would like to know if this is fixable as a bug or if there is any best practice and/or some manual intervention to make it work.

    Please install fix from OSS note 506603. After this, right-click .sapwsdl file and select "Run custom tool".

  • Any tool that generates a sample XML with some data given an xsd

    hello friends, is there any free tool availaible that generates a sample XML with some data given an xsd . please do let me know

    got it guys, xmlspy and stylus studio , neways thanks

  • Bex query that returns variable number of columns based upon variable value

    I have a request to create a query that, at excution time, has a variable for 'nbr of months', and based on the value entered by the user, returns data for only the specified number of months. Value that can be entered can vary from 1 to 12. A simple example is, if the user enters 1, then they would only want to see one column, and if they entered 6, then they'd like to see 6 columns in the workbook.  All suggestions on how to implement this dynamic columns on a workbook will be appreciated.
    Thanks.
    BN

    Hi,
    Do this->
    1) first create a New Structure in Rows-> Place your New Selection and drag your KF.
    2) Nw Create a New Formual under this structure. Now Create a Formula variable ( "ZFVXXX")with user-entry and ready for input and dimension as NUmber. and place in formula area. And hide this formula.
    3)Now Create a New Customer-Exit variable on 0CALMONTH name as "ZCECMON" with following atrribute->Mandatory, Range(Interval) and remove check for Ready for entry.
    4)Drag your 0CALMONTH in Rows above That Structure and restrict it to "ZCECMON".
    5) Now go to CMOD and write this code.
    INCLUDE ZXRSRU01 *
    DATA: L_S_RANGE TYPE RSR_S_RANGESID. 'In global area
    DATA: LOC_VAR_RANGE LIKE RRRANGEEXIT. 'In global area
    DATA: zmonth like /bi0/0calmonth.
    CASE I_VNAM.
    WHEN 'ZCECMON'.
    IF i_step = 2.
    LOOP AT I_T_VAR_RANGE INTO LOC_VAR_RANGE
    WHERE VNAM = 'ZFVXXX'.
    zyear = sy-datum(4).
    zmonth = sy-datum+4(2).
    l_s_range-low = zmonth.
    zmonth = zmonth + loc_var_range-low.
    l_s_range-HIgh = zmonth.
    l_s_range-sign = 'I'.
    l_s_range-opt = 'BT'.
    APPEND l_s_range TO e_t_range.
    ENDIF.
    ENDCASE.
    6) activate the porject and go to rsrt and run there first.
    Regards,
    San!
    Message was edited by: San!

  • Select function that returns multiple columns.

    Currently I have a function that will return 1 column and I can use that in a select statement. What I need is to return multiple columns from a table. In the function I have I return the street address from a table that holds information about dealers, I need to be able to also return the columns that contain the city, state, and zip code so it can be used in an sql select statement. How would I do this?
    My function:
    FUNCTION GET_ADDRESS(dealer_id IN number)
    RETURN tbl_dealer_info.c_street%TYPE AS
    v_rc tbl_dealer_info.c_street%TYPE;
    CURSOR get_dealer_cur IS
    SELECT c_street
    FROM tbl_dealer_info
    WHERE n_dealer_id = dealer_id;
    BEGIN
    v_rc := NULL;
    OPEN get_dealer_cur;
    FETCH get_dealer_cur INTO v_rc;
    IF get_dealer_cur%NOTFOUND THEN
    NULL;
    END IF;
    CLOSE get_dealer_cur;
    RETURN v_rc;
    EXCEPTION
    WHEN OTHERS THEN
    RETURN NULL;
    END GET_ADDRESS;
    My select statement:
    select GET_ADDRESS(1205) Street, DI.n_inactive_flag, DI.n_onhold_flag
    from tbl_dealer_info DI
    where DI.n_dealer_id = 1205;
    I would like to be able to select the street, city, state, and zip all in this select statement from the GET_ADDRESS function.
    Thanks,
    Lori Neirynck

    "The reality is you've probably already put your blinders on and you won't learn the best approach to solving your problem because you insist on asking a courtroom style question (just "yes" or "no" please)."
    Actually, I asked this question because I was looking for the best approach to my problem. I have an SQL statement that correctly selects everything it needs to from all 15 tables. The thing of it is it is very long and difficult to read. I wanted to try using functions so that I could change 12 AND/OR statements into 3 IF statements so everything is easier to read. I have received a couple of different ways to do this from other forums that assumed I knew what I was doing. I have gotten one to work, the other I'm still working on. I'll post the one that worked for others that want to know.
    SQL> insert into dealer_info values (1,'Me','13 success street', 'Wonder Town','Wonderland','1313');
    SQL> commit;
    SQL> create type t_address as object (
    2 street varchar2(100),
    3 city varchar2(30),
    4 state varchar2(30),
    5 zip varchar2(10));
    6 /
    Type created.
    SQL> create or replace function get_address (p_id number) return t_address
    2 is
    3 ret t_address := t_address(null,null,null,null);
    4 rec dealer_info%rowtype;
    5 begin
    6 select * into rec from dealer_info where id=p_id;
    7 ret.street := rec.street;
    8 ret.city := rec.city;
    9 ret.state := rec.state;
    10 ret.zip := rec.zip;
    11 return ret;
    12 end;
    13 /
    Function created.
    SQL> col name format a10
    SQL> col address format a70
    SQL> select name, get_address(id) address from dealer_info;
    NAME ADDRESS(STREET, CITY, STATE, ZIP)
    Me T_ADDRESS('13 success street', 'Wonder Town', 'Wonderland', '1313')
    1 row selected.
    -Lori

  • Need a function that return multiple rows

    Hi,
    I need a function that should return output of this query
    SELECT b.branding_code, c.name_desc
    FROM
    development.brandings b, godot.company c
    WHERE b.company_id = c.company_id;
    This above function return 30 rows and I am not giving any input
    Function using cursor,pipeline
    Please help
    Edited by: 1008783 on Jun 6, 2013 6:40 AM

    Hi,
    1008783 wrote:
    Hi
    Table A:
    Development schema
    branding_code,company_id
    Table B:
    Gogot schema
    name_desc,...Those aren't CREATE TABLE and INSERT statements. Post something that the people who want to help you can run on their own systems to re-create the problem and test their ideas.
    o/p:
    branding_code,name_desc
    I should return these column as o/p, no i/pA query will do that. There's no need for a function.
    There are good reasons for wanting a functin. If you have one, say what it is. Explain how you plan to use the function.
    Have you tried writing a function? Post your code. What specific problems did you have?

  • SQL query that returns exclusive rows from groups

    I'm using modified scott/tiger data for this.
    I've got two tables
    DEPT_X
    DEPTNO     DNAME             LOC     CODE_ID     SUB_DEPTNO
    10     ACCOUNTING     NEW YORK 111     101
    10     SALES             ATWN      111     102
    10     SALES             BTWN      112     103
    20     RESEARCH     DALLAS      111     201
    20     RESEARCH     CTWN      111     202
    30     SALES             CHICAGO      111     301
    40     OPERATIONS     BOSTON      112     401and
    BI_PD
    CODE_ID     PD_TYPE     BI_TYPE
    111          -1
    112     -1     I want to write a query that joins the code_ids of the two tables and lists out either only the records from DEPT_X who's code_ids have a -1 in the PD_TYPE(112) column and none of the code_ids that have a -1 in the BI_TYPE(111) column for each department or if that department has code_ids for the BI_TYPE (111), list out those rows. So for Deptno 10 you'll only get the row with SUB_DEPTNO = 103. But if for that DEPTNO= 20 you'll get the rows for both SUB_DEPTNO = 201 and 202.
    So the result should look like
    DEPTNO   SUB_DEPTNO
    10          103
    20          201
    20          202
    30          301.
    Basically I just want rows from each department that have code_ids = 111 not to show up if there are code_ids = 112.
    What is the query to do this?
    Message was edited by:
    user623359
    Message was edited by:
    user623359
    Message was edited by:
    user623359
    Message was edited by:
    user623359
    Message was edited by:
    user623359

    One way could be:
    Connected to:
    Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
    With the Partitioning, OLAP and Data Mining options
    SQL> with dept_x as (
      2      select 10 deptno, 'ACCOUNTING' dname, 'NEW YORK' loc, 111 code_id, 101 sub_deptno from dual
    union all
      3      select 10, 'SALES', 'ATWN', 111, 102 from dual union all
      4      select 10, 'SALES', 'BTWN', 112, 103 from dual union all
      5      select 20, 'RESEARCH', 'DALLAS', 111, 201 from dual union all
      6      select 20, 'RESEARCH', 'CTWN', 111, 202 from dual union all
      7      select 30, 'SALES', 'CHICAGO', 111, 301 from dual union all
      8      select 40, 'OPERATIONS', 'BOSTON', 112, 401 from dual ),
      9  --
    10  bi_pd as(
    11      select 111 code_id, null pd_type, -1 bi_type from dual union all
    12      select 112, -1, null from dual),
    13  --
    14  t as(
    15      select a.deptno,a.sub_deptno from dept_x a, bi_pd b
    16      where a.code_id = b.code_id and b.pd_type = -1)
    17  --
    18  select a.deptno,a.sub_deptno
    19  from dept_x a, bi_pd b
    20  where a.code_id = b.code_id and b.bi_type = -1 and 
    21        (a.deptno) not in (select deptno from t)
    22  union
    23  select deptno,sub_deptno from t;
        DEPTNO SUB_DEPTNO
            10        103
            20        201
            20        202
            30        301
            40        401

  • How to Display Columns when Query is returning No Columns?

    I am Creating a Load Status Dash Board and I want to Dispaly Columns when Load is Not Started  too. As of Now My query is returning no Results which needs to Modified and Display Columns and Status Not Started to it? Could you please suggest any solutions to it? Thanks

    Hi,
    if you like to show a message instead of NO RESULTS . then you could easily get it by changing the custom text in the properties
    if you want it in a table format . you need to have a table with some data according to the reporting requirement
    thanks

Maybe you are looking for

  • How to import multiple files to the frame area?

    How do I import multiple files to create animated GIF's. I know how to import multiple files into the Fireworks, but if I'm trying to create an animated gif that has alot of files, How do I get them into the frames area. It is really a pain importing

  • Want to block tracking for speed (page loading) more than privacy. Will it help? What are appropriate addons?

    When loading pages, new sites off of Google new for instance, I notice that the page takes a very long time to load while analytics load for google, facebook, advertisers, etc, in the bottom left of the screen. It seems to have gotten much much worse

  • Find the usage for each device on the router per day or month (megabytes per mac address)

    HI -- We have a single cable connection and a router network with over 10 unrelated users in our complex.  We want to keep usage fair, the network unstressed and to identify machiines that might have viruses or otherwise be using more than the owner

  • New subscription but dont want instal

    Hi I have searched the forum but cant find an answer to this. I just moved into a new ground floor flat - the building is 5 high so i understand i would need to pay a special install cost and get a special team out The problem i have is there is a go

  • Aperture Screen Resolution

    I have used Apple Aperture in the past and got disgusted with it because the picture resolution is flat, fuzzy and lacking in color ... compared with other software like Canon Digital Photo Professional and Photoshop CS5. I recently download some pic