Include column name in results

How do i include my column names as the first row of my results?

Hi,
Be careful with different datatypes. Example:
SQL> desc employees
Name           Type         Nullable Default Comments                                                                                                                                                                                 
EMPLOYEE_ID    NUMBER(6)                     Primary key of employees table.                                                                                                                                                          
FIRST_NAME     VARCHAR2(20) Y                First name of the employee. A not null column.                                                                                                                                           
LAST_NAME      VARCHAR2(25)                  Last name of the employee. A not null column.                                                                                                                                            
EMAIL          VARCHAR2(25)                  Email id of the employee                                                                                                                                                                 
PHONE_NUMBER   VARCHAR2(20) Y                Phone number of the employee; includes country code and area code                                                                                                                        
HIRE_DATE      DATE                          Date when the employee started on this job. A not null column.                                                                                                                           
JOB_ID         VARCHAR2(10)                  Current job of the employee; foreign key to job_id column of the
jobs table. A not null column.                                                                                         
SALARY         NUMBER(8,2)  Y                Monthly salary of the employee. Must be greater
than zero (enforced by constraint emp_salary_min)                                                                                       
COMMISSION_PCT NUMBER(2,2)  Y                Commission percentage of the employee; Only employees in sales
department elgible for commission percentage                                                                             
MANAGER_ID     NUMBER(6)    Y                Manager id of the employee; has same domain as manager_id in
departments table. Foreign key to employee_id column of employees table.
(useful for reflexive joins and CONNECT BY query)
DEPARTMENT_ID  NUMBER(4)    Y                Department id where employee works; foreign key to department_id
column of the departments table
SQL> SELECT 'EMPLOYEE_ID' FROM DUAL UNION ALL SELECT E.EMPLOYEE_ID FROM EMPLOYEES E;
SELECT 'EMPLOYEE_ID' FROM DUAL UNION ALL SELECT E.EMPLOYEE_ID FROM EMPLOYEES E
ORA-01790: expression must have same datatype as corresponding expressionMaybe you have to use to_char function to avoid this problems
SQL> SELECT 'EMPLOYEE_ID' FROM DUAL UNION ALL SELECT to_char(E.EMPLOYEE_ID) FROM EMPLOYEES E;
'EMPLOYEE_ID'
EMPLOYEE_ID
100
101
102
103Regards,

Similar Messages

  • Exporting data to a csv file and include column names

    I am creating a SSIS package which creates a .csv file.  The package works fine except it is not putting the column names as the first row.
    How do I get the column names to also export?
    Thanks,
    ~John

    SQL Server 2012 T-SQL has the new FORMAT command:
    SELECT FORMAT(CONVERT(MONEY,123456.78),'c0','en-US'), -- $123,457
    FORMAT(CONVERT(MONEY,123456.78),'c2','en-US'), -- $123,456.78
    FORMAT(CONVERT(MONEY,123456.78),'c2','en-GB'), -- £123,456.78
    FORMAT(CONVERT(MONEY,123456.78),'c2','de-DE') -- 123.456,78 €
    Prior to SS 2012:
    SELECT CONVERT(varchar(40),CONVERT(MONEY,123456.78),1) -- 123,456.78
    SSIS Import/Export Wizard:
    http://www.sqlusa.com/bestpractices/ssis-wizard/
    Kalman Toth SQL 2008 GRAND SLAM
    New Book: SQL Programming & Database Design Using Microsoft SQL Server 2012

  • How to select even the column names of a table?

    Hello All,
    Is there a way to select even the column names of a table in the select statement?
    My select from a table (say X) is in a SQL* Plus script that gets invoked by application tier and displays data in the application tier window. User's can then copy the data into a spreadsheet and do their processing. However, I need to give them the column names too along with the data.
    Thanks,
    Chiru

    If there is a middle tier that is selecting and
    displaying the data, and that's what the users are
    copying from, the middle tier would have to address
    its presentation of the data to allow users to
    include column names. If this is a common task, the
    application should probably be modified to give users
    the option of downloading the data in a spreadsheet
    directly rather than forcing them to copy and paste
    data.Thanks for the reply.
    The users don't have to copy paste. The application tier has an options in the "Tools" menu item which allows them to copy the entire output to a file (in my case a txt file which is a pipe delimited). Then they have to do text to columns to get the data into each column of the spreadsheet. I could have directly called the stored procedures from the application tier and created ".csv" files and FTP'd them to the user's folders. However, I am having to go this round about because, I am not getting enough support from the LAN team in FTP'ing etc.
    OK I'll think of another workaround.
    Thanks,
    Chiru

  • Column Name change in IR

    Hi,
    I want to display the different column name in dashboard other than the column name in result set. for eg: I have the results with column name emp_id. now i want to display this column name as Employee_ID in dashboard. How to do this?
    Thanks in Advance...

    Either change the column name in the Query on the Request Line it does not impact the column selected similar to the SQL Select statement AS
    OR
    Add a Computed Column in Results referencing emp_id and then Hide emp_id.
    Wayne Van Sluys
    TopDown Consulting

  • JDBC ResultSet lowercase Column names

    Hi,
    My group has a body of DBMS access beans which use lowercase column names for result set get(s)* ..ie rs.getString("empno");.
    Are current JDBC context uses KIVA\NAS.
    We've recently attempted to use these beans under Oracle JDBC OCI (type 2). We've noticed that Oracle JDBC prefers rs.getString("EMPNO") .. or rs.getString(1).
    Is there a way around this? Or do we have some serious changing to do?
    Thanks in advance.

    The column names our current driver takes in getString() is not case-sensitive. I am not sure whether that was the case with some previous versions. Is it possible that you can try it on the 8.1.6 driver?

  • Incorrect column names returned using OCIDescribeAny

    I am trying to retrieve column names using OCIDescribeAny and OCIAttrGet api calls.
    The column names and the lengths of the column names returned by OCIAttrGet calls are usually correct.
    Except when the length of column names are divisible by 4, an extra tab is padded at the end of the returned string by OCIAttrGet.
    The length returned by the call is fine.
    Example 1.
    Column Name:
    CITY
    Results Returned by OCIAttrGet:
    column name: CITY\t
    column length: 4
    Example 2.
    Column Name:
    PHONE_NUMBER
    Results Returned by OCIAttrGet:
    column name: PHONE_NUMBER\t
    column length: 12
    Does anyone has experience with this?
    Edited by: simon780 on Mar 13, 2010 2:48 PM
    Edited by: simon780 on Mar 13, 2010 4:03 PM

    Thank you for answering my question, I thought I was doing something wrong, since this is my very first time using oci.
    I do see non-null terminated strings mentioned from places to places on the oracle docs, but I don't see it mentioned specifically on the attribute OCI_ATTR_NAME.
    Anyway, as long as I have the string length returned by the function call, then it's all good. Thank you again!!

  • 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

  • Getting the name of the table of a column in a result

    I am connected via ODBC (3.52) to an Oracle 8i Db in a Windows 2000 application and want to get the name of the table a column of the result belongs to. I tried SQLColAttribute and SQLGetDescField with SQL_DESC_TABLE_NAME (that works fine with MsAccess), but always get an empty string. Is there another way of getting such information, or do I need another driver, or am I lost in space and time now?

    You can query ALL_TAB_COLS directly if you want.

  • Result of an SQL query as a Column name of another query

    Hi Friends,
    Can we use a result of a SQL Query as a column name of another table to retrieve data. If so please help me.
    For eg :
    I have a table where is store numbers;
    select col1 from table1 where col1='5';
    and i have another table where .. this value of col is a column name..
    select ( select col1 from table1 where col1='5') from table2;
    Thanks in advance.

    Hi,
    ORAFLEX wrote:
    Hi Friends,
    Can we use a result of a SQL Query as a column name of another table to retrieve data. If so please help me.
    For eg :
    I have a table where is store numbers;
    select col1 from table1 where col1='5';
    and i have another table where .. this value of col is a column name..
    select ( select col1 from table1 where col1='5') from table2;
    Thanks in advance.Do you really mean that?
    select col1 from table1 where col1='5';That query will always return either '5' or nothing. Whatever you're trying to accomplish with that, you can do with an EXISTS query.
    Perhaps you meant to reference two different columns in that query:
    select col1 from table1 where col2='5';In that case, sorry, no, you can't do that without resorting to dynamic SQL.
    If the same column is used throughout the query (but could change every time you run the query), then the dynamic SQL might be pretty easy. In SQL*Plus, for example, you could use substitution variables, defined in another query at run-time.
    If there are only a few possible values that the sub-query could possibly return, and you know what they all are, then you can fake a dynamic query like this:
    SELECT     CASE     ( SELECT  col1
                FROM       table1
                WHERE       col2     = '5'
              WHEN  'BONUS'     THEN  bonus
              WHEN  'COMM'     THEN  comm
              WHEN  'SAL'     THEN  sal
         END     AS col1
    FROM     table2
    ;Sorry to give such a vague answer, but it's the best I can do with the information I have.
    It would help if you posted a little sample data (CREATE TABLE and INSERT statments for both tables), and the results you want to get from that data. If you want to pass a parameter to the query, give the results you want for a couple of different parameters.

  • Column name in include column contex menu

    When I select Include column from column context menu in pivot table, colum names listed (for calculatd items) are the column formulas and not the column headings.
    There is a way to force the column context menu to use column headings instead?
    Thanks
    Luc

    When I select Include column from column context menu in pivot table, colum names listed (for calculatd items) are the column formulas and not the column headings.
    There is a way to force the column context menu to use column headings instead?
    Thanks
    Luc

  • How to include columns with a space in name in clientcontext load method in JSOM

    Hi Gurus,
    I have a situation where I need to read a list that has a column 'Repositary Name'.
    While I am reading the list in my JSOM I need to load this column in the clientcontext.load method.
    My code likes this below.
    this.collListItem = list.getItems(camlQuery);
        ctx.load(collListItem, 'Include(Title, 'Repositary Name')')
    The Issue is I can not load this 'Repositary Name' column. I tried with its internal name, removing the space, putting the name in single quote but nothing works.
    Please advice how to include a column in clientcontext.load method that has a space in its name .
    Changing the column is not a option and I have to have call it before I use it my Async Methods.

    Hi,
    If I am getting your issue correctly, I think you should put _x0020_ in place of space in your column name. In your case try Repositary_x0020_Name.
    ***If my post is answer for your query please mark as answer***
    ***If my answer is helpful please vote***

  • How to write a Query a table and the return result is the column name

    Hi All
    Pls advise how to write a query whereas the return result is the
    column name.
    I know there is describe <table_name>;
    Is there any other ways?
    Pls advise
    Tj
    Edited by: user600866 on Oct 14, 2008 12:13 AM

    Data Dictionary table user_tab_columns has all the column names. You can query that and get what ever you want.
    To get the column list of a table just query
    select *
      from user_tab_columns     
    where table_name = <your_table>Edited by: Karthick_Arp on Oct 14, 2008 12:18 AM

  • What is the order of Column Names in Sqlite query results?

    I am writing an application using Adobe Air, Sqlite, and Javascript.
    After writing the following select statement:
              SELECT field1, field 2, field 3, field 4 FROM TableA;
    I would like to get the columnName/data combination from each row -- which I do successfully with a loop:
              var columnName="";
              for (columnName in selResults.data[i]) {
                   output+=columnName + ":" + selResultsdata[i][columnName] + ";";
    My issue is that the column names come out in a different order every time I run the query and never once have they come out in the desired order -- field 1, field 2, field 3, field 4.  If I run the query in Firefox's Sqlite Manager, the columns come out in the "proper" order. When I run them in Adobe Air, the order will be the same if I run the query mulitple times without closing the app.  If I make a change such as declaring the columnName variable with "" before the for column, or declare it as (var = columnName in selResults.data) , then the order changes.  If I shut down my app and re-open after lunch and run query, it comes out in another order.  At this time, I'm not interested in the order of the rows, just the order of the columns in each output row.  I've even tried assiging an index to columnName which seems to just pick up a single letter of the columnName.
    I'm in the process of changing my HTML presentation of the data to assign a precise columnName to an HTML table title, but I'm reluctant to let go of the above concept as I think my separation of HTML/presentation and Javascript would be better if I could use the solution described above.
    So, does anybody know how to force the order of the columnNames in my output -- or what I'm doing to cause it to come out in a different order?
    Jeane

    Technically there isn't any "order" for the return columns. They aren't returned as an Array -- they're just properties on an Object instance (a "generic object"). The random order you're seeing is the behavior of the for..in loop iterating over the properties of the object. Unfortunately, with a for..in loop there is no guaranteed order for iterating over properties (and, as you've seen, it tends to vary wildly).
    The only solution is to create your own list of the column names and sort it the way you want to, then use that to create your output. For example, use the for..in loop to loop over the properties, but rather than actually get the values, just dump the column names into an Array:
    var columnName="";
    var columns = [];
    for (columnName in selResults.data[i]) {
        columns.push(columnName);
    columns = columns.sort(); // just uses the default alphabetical sort -- you would customize this if desired
    var j = 0;
    for (j = 0; j < columns.length; j++) {
        columnName = columns[j];
        output+=columnName + ":" + selResultsdata[i][columnName] + ";";

  • How to Include Double Quotes in the Column Name

    Hi,
    I am using Dynamic Sql for creating the columns of a table. I am getting a situation where the user will give the double quotes for some column names. So,Can we add double quote to the column name.
    Thanks in advance.
    Regards,
    Alok Dubey

    http://download.oracle.com/docs/cd/B28359_01/server.111/b28286/sql_elements008.htm
    However, neither quoted nor nonquoted identifiers can contain double quotation marks or the null character

  • Including item names in report column headings

    I have a report where I want to use page items in the column headings. Trying to define these using (for example) &P1_ITEM. in the report definition / custom heading does not seem to work. I can define a simple PL/SQL function to return the heading, but I have many columns and it will mean that I'll have to define a function for each column name which does not seem v elegant. Am I missing something obvious?
    Thanks Simon

    Hi Simon
    Column Attributes
    Headings Type:  Column Names  Column Names (InitCap)  Custom  PL/SQL  None choose PL/SQL
    Function returning colon delimited headings:
    DECLARE
    vHEADINGS VARCHAR2(1000);
    BEGIN
    vHEADINGS := 'NAME:SURNAME:CODE:CELL_NR:&P1_CELL_1.:&P1_CELL_2.:&P1_CELL_3.:' || :XXX || ':' || :YYY || ':' || :ZZZZ || :A || ':' || :B || ':' || :C;
    RETURN vHEADINGS;
    END;Regards
    Mel

Maybe you are looking for

  • Dictation in the classroom

    After Easter, I will be starting a project to develop the use of Speech Recoginition software in the classroom (Known as Dictation on Apple Products).  In the early days of this technology (15+ years ago) it was necessary to teach the software to rec

  • Billing document with email output

    Hi, I have completed all the config to get my billing documents to output via email. However i cannot get VF31 to automatically generate the output for these. Only works if i manually assign output with VF02. Can anyone advise in simple steps what ne

  • Method for Saving the attendence data

    Dear All,              We are implementing the HR,MM,FI,SD module and also implementing  the Kronos Time Machine for Time details. I got the text file in which employee attendence data is mentioned  from the kronos system.Now which way i have to used

  • Should I Unistall PrCC Before Installing PrCC 2014?

    Hi Guys I'm about to install v.2014 on my Dell Precision M6700 Laptop (Win7, 64bit) but before doing so, should I uninstall the original CC version? Regards, Graham

  • Security query: Tomcat on Tiger

    Last night I discovered that I did something idiotic about two years ago. I would like to know just how idiotic. I was trying to get something - I no longer recall what - working which required Tomcat. I therefore installed SISU Works package (see ht