Referencing table created column names

probably a really simple solution but I'm having trouble,
when you create a new column in an SQL query:
example - ISNULL(row1, 99999) AS ideal
how do I then reference that column within the same query?
(example - (ideal + 10) AS newideal) When i refer to it as
ideal I get an error stating that
ideal is an invalid column name (presumably meaning it
cannot be found in any of the tables in the from clause.
is there a special prefix i need or other such system in
order to reference columns created within a query whilst still in
said query??
Thanks

Can't do it by alias, as you would just repeat the
calculation/function/whatever and add whatever additional "stuff"
to create your new column.
ISNULL(row1, 99999) AS ideal,
ISNULL(row1, 99999)+10 AS newideal
etc.
Phil

Similar Messages

  • Referencing table-aliased column names in JDBC

    We are attempting to port an application from MySQL to Oracle 8i, using JDBC as the database connection technology. The app has SQL statements using joins, e.g.
    SELECT A.*, B.* FROM table1 A, table2 B WHERE A.field1=B.field2 etc
    Often the tables have columns sharing the same name, so the table alias is required to avoid ambiguity (e.g. both tables have column ID, so they must be referenced as A.ID or B.ID).
    When using MySQL, the Java code
    String strField = rset.getString( "SURNAME" );
    or
    String strField = rset.getString( "A.SURNAME" );
    both succeed if the column name is unique, and if it is not unique, only the second form works. However, with Oracle, the second form never works, even though the column name is a valid column in the table aliased as A. Providing the whole table name does not work either:
    String strField = rset.getString( "table1.SURNAME" );
    If the Oracle JDBC driver does not support the {table-alias}.{column-name} syntax, then presumably the only way to reference ambiguous columns in joins is to supply the column number instead. (e.g. getString( 14 )). Our application generates dynamic SQL, and having to do this would be a MAJOR problem.
    We are currently using Oracle 8i - might this have been fixed in the move to 9i?
    Many thanks for any help,
    Steve Francis,
    London, UK.

    Can't do it by alias, as you would just repeat the
    calculation/function/whatever and add whatever additional "stuff"
    to create your new column.
    ISNULL(row1, 99999) AS ideal,
    ISNULL(row1, 99999)+10 AS newideal
    etc.
    Phil

  • Migrating from Sql Server tables with column name starting with integer

    hi,
    i'm trying to migrate a database from sqlserver but there are a lot of tables with column names starting with integer ex: *8420_SubsStatusPolicy*
    i want to make an offline migration so when i create the scripts these column are created with the same name.
    can we create rules, so when a column like this is going to be migrated, to append a character in front of it?
    when i use Copy to Oracle option it renames it by default to A8420_SubsStatusPolicy
    Edited by: user8999602 on Apr 20, 2012 1:05 PM

    Hi,
    Oracle doesn't allow object names to start with an integer. I'll check to see what happens during a migration about changing names as I haven't come across this before.
    Regards,
    Mike

  • List tables and column names a stored procedure is querying

    Hello,
    Is there a way to list tables and column names that a stored procedure is querying, i.e, selecting from, using T-SQL?  If yes, is there a way to also show data types for the columns that a stored procedure is querying, i.e, selecting from?
    Thank you,  
    Lenfinkel

    One way to view the dependencies of an object is to use SSMS; navigate to the object, right click and select "view dependencies".  However this does not tell you what columns are being referenced by the Stored Procedure.
    One way to view what is being referenced by a stored procedure is to run something like
    select
    text
    from syscomments
    where
    id in
    (select id
    from sysobjects
    where
    name
    =[Your Object Name]
    And xtype
    in
    ('p','P')
    Please click "Mark As Answer" if my post helped. Tony C.

  • Toplink JPA forces database table and column names to UPPERCASE! Why?

    I have recently experienced using Toplink JPA while using glassfish ... migrating an existing application to EJB 3.0 persistence. Toplink JPA, as implemented in glassfish, forces tablenames and column names from my code to be uppercase in select statements, etc. as then submitted to the database. Why? I cannot find anything in the EJB 3.0 specs on persistence that even suggests this.
    This created a serious problem for me, in my application. For my code to work I had to change the names of the database tables to all uppercase, even though that meant other of my applications, already written using the original mixed case names of the databases, will no longer work unless I revise the code in those applications! (I am using mySQL as my database.)
    In both Unix/Linux and Java, which are both case sensitive, If I wanted names of files or other items to be uppercase, I would have written them that way. I do not expect some middleware piece of software to muck around with the case of text I have put into my code.
    I am hopeful this 'feature' of the reference implementation of the EJB Persistence API will be corrected in a subsequent version. [Maybe you can tell I am not happy!]
    Thanks for listening to my rant.

    Robert,
    I found that the name I specify in all of my @Table, @Column, ... annotations is used with the case as it is provided.
    If TopLink determines the schema information through defaults then the names it comes up with are definitely upper cased by default.
    Are you specifying the schema information that you want in annotations or XML?
    Doug

  • How to update a table whose column name contains an ampersand?

    Hello,
    I am needing to update a column whose column name contains an ampersand, and cannot figure out a way to do this. Option is not there to have the column name changed.
    Ex:
    UPDATE aircrafts
    SET d&f = 1
    WHERE aircraft_code = '737';
    this returns an error of missing an = sign
    I tried:
    SET 'd'||'&'||'f' = 1
    doesnt work
    Any help is greatly appreciated.
    Thanks,
    Laura

    SET DEFINE OFF
    will stop interpreting the & sign as starting of a lexical parameter on the client.
    Not sure if you have that issue there.
    & might also be a not allowed character in normal column names (didn't test).
    In that case you might need to put the column name in ".
    +example+
    {code}
    UPDATE aircrafts
    SET "d&f" = 1
    WHERE aircraft_code = '737';
    {code}
    Be aware that in this case the column name must be spelled exactly like it was when the table was created.
    Included upper/lower case.
    {code}
    UPDATE aircrafts
    SET "D&F" = 1
    WHERE aircraft_code = '737';
    {code}

  • SQL text parsing to obtains referenced tables and columns

    I wonder if anyone has a method of scanning an SQL statement to retrieve tables and columns referenced. EG:
    select
    f.cola, f.colb, f.colc, b.cold
    from
    foo f, bar b
    where
    f.cola=b.cola and f.colb=b.colb
    order by f.colz, b.colawould provide
    Tables
    foo
    bar
    Columns
    foo.cola [SELECT] [WHERE]
    foo.colb [SELECT] [WHERE]
    foo.colc [SELECT]
    foo.colz [ORDER BY]
    bar.cola [WHERE] [ORDER BY]
    bar.colb [WHERE]
    bar.cold [SELECT]The reason is that I'd like to query through several SQL scripts and validate tables and columns in a new version of the ERP system exist

    That query with date substitution should also work. Are you seeing some errors?
    SQL> explain plan for select * from scott.emp where hiredate = to_date(':some_date', 'dd-mon-yyyy') ;
    Explained.
    SQL> @utlxpls
    PLAN_TABLE_OUTPUT
    | Id  | Operation            |  Name       | Rows  | Bytes | Cost  |
    |   0 | SELECT STATEMENT     |             |     1 |    40 |     2 |
    |*  1 |  TABLE ACCESS FULL   | EMP         |     1 |    40 |     2 |
    Predicate Information (identified by operation id):
       1 - filter("EMP"."HIREDATE"=TO_DATE(':some_date','dd-mon-yyyy'))
    Note: cpu costing is off
    14 rows selected.
    SQL>

  • Displaying table and column names

    i have a user that created a table, he is not sure of the name of the table. how do i display a list of tables and display the column names within a table??

    You would need to know who the user is, or alter the following script.
    The script waits for 2 entries:
    1- the tablenames that start with the first characters entered;
    2- the columns that start with the first characters entered;
    (If you want to search for "any" tables and/or columns that contain the charatcers you enter, preceed the parameters entered with a % sign).
    (If you want to search for "any" table or character, do not enter anything.
    This is a "raw" script that should do job. I think it should do the minimum you are looking for.
    SET PAGESIZE 50
    SET LINESIZE 120
    SET TIMING ON
    COLUMN OWNER HEADING 'OWNER' FORMAT A12
    COLUMN TABLE_NAME HEADING 'TABLE NAME' FORMAT A30
    COLUMN COLUMN_NAME HEADING 'COLUMN NAME' FORMAT A30
    COLUMN DATA_TYPE HEADING 'TYPE' FORMAT A10
    COLUMN DATA_PRECISION HEADING 'PREC' FORMAT 99G999
    COLUMN DEFAULTVAL HEADING 'DEF VALUE' FORMAT A10
    COLUMN INDEX_NAME HEADING 'INDEX NAME' FORMAT A30
    COLUMN INDEX_TYPE HEADING 'TYPE OF INDEX' FORMAT A27
    COLUMN UNIQUENESS HEADING 'UNIQUE' FORMAT A3
    COLUMN PARAMETERS HEADING 'PARAMETERS' FORMAT A500 NEWLINE
    -- Query
    SELECT DISTINCT --COUNT(*)
    C.TABLE_NAME,
    C.COLUMN_NAME,
    C.DATA_TYPE,
    C.DATA_LENGTH,
    C.DATA_PRECISION
    FROM ALL_TAB_COLUMNS C,
    ALL_CONS_COLUMNS CC1
    WHERE
    (C.COLUMN_NAME = CC1.COLUMN_NAME(+)
    AND UPPER(C.TABLE_NAME) = UPPER(CC1.TABLE_NAME(+)))
    AND UPPER(C.TABLE_NAME) LIKE UPPER('&PARAM1%')
    AND UPPER(C.COLUMN_NAME) LIKE UPPER('&PARAM2%')
    --AND OWNER = 'SYS'
    --AND DATA_TYPE = 'DATE'
    --AND DATA_TYPE != 'CLOB'
    --AND DATA_TYPE != 'LONG'
    ORDER BY C.TABLE_NAME, C.COLUMN_NAME;
    Hope this helps.

  • How to get table and column names thats being used in SQL , that's generating all my reports on SSRS.

    Good day,
    I searched through the forum and cant find anything.
    I have around 300 published reports on SSRS and we are busy migrating to a new system.
    They have already setup their tables on the new system and I need to provide them with a list of table names and column names that are being used currently to generate the 300 reports on SSRS.
    We use various tables and databases to generate these reports, and will take me forever to go through each query to get this info.
    Is it at all possible to write a query in SQL 2008 that will give me all the table names and columns being used?
    Your assistance is greatly appreciated.
    I thank you.
    Andre.

    There's no straightforward method for that I guess. There are couple of things you can use to get these details
    1. query the ReportServer.dbo.Catalog table
    for getting details
    you may use script below for that
    http://gallery.technet.microsoft.com/scriptcenter/42440a6b-c5b1-4acc-9632-d608d1c40a5c
    2. Another method is to run the reports and run sql profiler trace on background to retrieve queries used.
    But in some of these cases the report might be using a procedure and you will get only procedure. Then its upto you to get the other details from procedure like tables used, columns etc
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • How to read the data from an internal table,when column names are known

    Hi All
    I have a specific requirement. I got an internal table with many fields (let it be my_tab).  Some of the fieldnames (column names in internal table my_tab) are stored in separate internal table(let it be my_fields).
    I need to store/read data corresponding to the fields (whose name is stored in my_fields) from my_tab.
    I am able to build dynamic table (referred by field-symbol) with respect to the given field names in my_fields.
    But i am unable to read the data corresponding to the fieldnames from my_tab.
    Please provide  me some pointer in this regard.
    Regards
    Swetabh Shukla

    HI All
    Thanks for the prompt response. I got solution for my question. Please check below thread. For quick reponse i posted my question in one more category. Thanks to all of you.
    How to read internal table w.r.t. fieldnames stored in other table

  • Check the table and column name in R12 web screen

    Hello Friends
    Please any body can tell me how can I find out the table name and column name in web based forms like supplier, customer in R12. In 11i I can find out the table name and column name from help menu by record history and diagnostic -> examine menu.
    Thansk
    Makshud

    Hi,
    Please see (Note: 741366.1 - How to get Supplier table information? How to get About this Page link in OA page in R12).
    Thanks,
    Hussein

  • Column values in table equal column names in other table (unpivot? cross apply?)

    2 tables:
    CREATE TABLE Requirement
     reqID int IDENTITY(1,1) PRIMARY KEY,
     req_result_id numeric(10,0) NOT NULL,
     description varchar(200),
     heading varchar(100),
     GO
    INSERT INTO Requirement VALUES (5296,'Cold pack','HH19_5');
    INSERT INTO Requirement VALUES (5296,'Band-Aids','HH19_6');
    INSERT INTO Requirement VALUES (5296,'First aid cream','HH19_7');
    INSERT INTO Requirement VALUES (5296,'Tape','HH19_8');
    INSERT INTO Requirement VALUES (5296,'Gloves','HH19_9);
    INSERT INTO Requirement VALUES (5296,'Bandages','HH19_10');
    INSERT INTO Requirement VALUES (5296,'Hand sanitizer','HH19_11');
    INSERT INTO Requirement VALUES (5296,'Scissors','HH19_12');
    INSERT INTO Requirement VALUES (5296,'Poison control information','HH19_13');
    INSERT INTO Requirement VALUES (5296,'Name','HH02');
    GO
    CREATE TABLE Response
     respID int IDENTITY(1,1) PRIMARY KEY,
    req_result_id numeric(10,0) NOT NULL,
     HH02 varchar(200),
     HH19_5 varchar(20),
     HH19_6 varchar(20),
     HH19_7 varchar(20),
     HH19_8 varchar(20),
     HH19_9 varchar(20),
     HH19_10 varchar(20),
     HH19_11 varchar(20),
     HH19_12 varchar(20),
     HH19_13 varchar(20),
     GO
    INSERT INTO Response VALUES (33,'Mary',7,8,9,10,11,12,13,14,15);
    INSERT INTO Response VALUES (35,'Barbara',7,8,9,10,11,12,13,14,15);
    INSERT INTO Response VALUES (144,'Melissa',7,8,9,10,11,12,13,14,15);
    INSERT INTO Response VALUES (146,'Missy',7,8,9,10,11,12,13,14,15);
    INSERT INTO Response VALUES (5296,'Pamela',7,8,9,10,11,12,13,14,15);
    GO
    Result:
    description
    heading
    response
    Name
    HH02
    Pamela
    Bandages
    HH19_10
    12
    Hand sanitizer
    HH19_11
    13
    Scissors
    HH19_12
    14
    Poison control information
    HH19_13
    15
    Cold pack
    HH19_5
    7
    Band-Aids
    HH19_6
    8
    First aid cream
    HH19_7
    9
    Tape
    HH19_8
    10
    Gloves
    HH19_9
    11
    For now, I'm using where req_result_id = 5296. Only one row from the Response table is selected.
    I'm playing with unpivot and cross apply. I might use two CTE's but am not yet sure how to join them. I would just like to see what others here suggest.
    I only need help with T-SQL - not table design.
    Let me know if you need more info or if I need to reformat the expected output to make it legible.
    Thanks for any suggestions.

    CREATE TABLE Requirement
    reqID int IDENTITY(1,1) PRIMARY KEY,
    req_result_id numeric(10,0) NOT NULL,
    description varchar(200),
    heading varchar(100),
    GO
    INSERT INTO Requirement VALUES (5296,'Cold pack','HH19_5');
    INSERT INTO Requirement VALUES (5296,'Band-Aids','HH19_6');
    INSERT INTO Requirement VALUES (5296,'First aid cream','HH19_7');
    INSERT INTO Requirement VALUES (5296,'Tape','HH19_8');
    INSERT INTO Requirement VALUES (5296,'Gloves','HH19_9');
    INSERT INTO Requirement VALUES (5296,'Bandages','HH19_10');
    INSERT INTO Requirement VALUES (5296,'Hand sanitizer','HH19_11');
    INSERT INTO Requirement VALUES (5296,'Scissors','HH19_12');
    INSERT INTO Requirement VALUES (5296,'Poison control information','HH19_13');
    INSERT INTO Requirement VALUES (5296,'Name','HH02');
    GO
    CREATE TABLE Response
    respID int IDENTITY(1,1) PRIMARY KEY,
    req_result_id numeric(10,0) NOT NULL,
    HH02 varchar(200),
    HH19_5 varchar(20),
    HH19_6 varchar(20),
    HH19_7 varchar(20),
    HH19_8 varchar(20),
    HH19_9 varchar(20),
    HH19_10 varchar(20),
    HH19_11 varchar(20),
    HH19_12 varchar(20),
    HH19_13 varchar(20),
    GO
    INSERT INTO Response VALUES (33,'Mary',7,8,9,10,11,12,13,14,15);
    INSERT INTO Response VALUES (35,'Barbara',7,8,9,10,11,12,13,14,15);
    INSERT INTO Response VALUES (144,'Melissa',7,8,9,10,11,12,13,14,15);
    INSERT INTO Response VALUES (146,'Missy',7,8,9,10,11,12,13,14,15);
    INSERT INTO Response VALUES (5296,'Pamela',7,8,9,10,11,12,13,14,15);
    GO
    ;with mycte as (
    select respID,req_result_id,response,heading from Response
    cross apply (values
    ([HH19_5],'HH19_5')
    ,([HH19_6],'HH19_6')
    ,([HH19_7],'HH19_7')
    ,([HH19_8],'HH19_8')
    ,([HH19_9],'HH19_9')
    ,([HH19_10],'HH19_10')
    ,([HH19_11],'HH19_11')
    ,([HH19_12],'HH19_12')
    ,([HH19_13],'HH19_13')
    ,([HH02],'HH02') ) d(response,heading)
    WHERE req_result_id=5296 )
    select description,r.heading,response from Requirement r
    inner join mycte m on r.req_result_id=m.req_result_id and r.heading=m.heading
    Order by Case When len(r.heading)=4 then 1 Else 2 END, Len(Replace(r.heading,'HH19_','')) desc
    drop table Requirement,Response

  • Query to Find Table and Column Name by using a value

    Dear Legends,
    I hope and surfed in our forums and google to find the Table Name and Column Name by having a value(Number/String). And my where clauses are
    where owner NOT IN ('SYS','SYSTEM') and
          data_type IN ('CHAR','VARCHAR2','NUMBER')
    May I have your help for building the query. and my query as follows
    select a.owner, c.column_name, c.data_type, c.owner, c.table_name
    from dba_objects a, all_tab_cols c
    where a.owner NOT IN ('SYS','SYSTEM') and
    where c.owner NOT IN ('SYS','SYSTEM') and
    where c.data_type IN ('CHAR','VARCHAR2')
    order by a.owner
    Thanks,
    Karthik

    You can use
    select * from user_tab_columns a, user_tables b
    where a.table_name = b.table_name
    and  a.data_type in ('NUMBER', 'VARCHAR2', 'NCHAR', 'CHAR');
    Or if you want to user DBA_* tables, you can use.
    select * from dba_tab_columns a, dba_tables b
    where a.table_name = b.table_name
    and a.owner = b.owner
    and  a.data_type in ('NUMBER', 'VARCHAR2', 'NCHAR', 'CHAR')
    and b.owner not in ('SYS', 'SYSTEM');
    And now when I look a bit more closely, you don't need DBA_TABLES there. dba_tab_columns alone is sufficient. And requirement is still not clear yet. Why you need a group by there? If I get it right, you can use this.
    select * from dba_tab_columns a
    where a.data_type in ('NUMBER', 'VARCHAR2', 'NCHAR', 'CHAR')
    and a.owner not in ('SYS', 'SYSTEM');
    Whether you use group by or not, the query will give you the same output.
    Ishan

  • Generating mixed case for table and column names

    I trying to get table definition from Oracle 9i database into my toplink workbench
    (version 9.0.3), the column names and table names are capitilized by
    default, how do I change this to be mixed case? Thanks

    I'm not sure why you want them changed. The Oracle database by default is case insensitive, which in essence means it converts everything to upper case when a case is not specified (which can be done by wrapping it in quotes). Unfortunately, Java strings are case sensitive. This means that if you try searching resultsets for "TableName" when the database driver is returning "TABLENAME", you will run into problems. It is probably better to have your project match your database as closely as possible to avoid any issues later on.
    That said, I don't know of a way to automatically have the workbench use mixed case names - it uses the strings as they are returned from the database. I believe you will need to manually change the table names if you want them to be different than what you have imported.
    Best Regards,
    Chris

  • How to view all tables and column names from a remote database

    Hey Guys,
    I have a database in a remote server. I have the db link and the schema name.. Now i want to view all the tables in the remote database with column names.. I dont have access to that database using sql developer.. But i can view some tables using the db link..Is there any way i can view all the tables with the column names?

    user10683742 wrote:
    Dont think i have DBA access..It gives the following error
    ORA-00942: table or view does not exist
    00942. 00000 - "table or view does not exist"You don't have to have 'dba' access, per se. You just have to have SELECT ALL TABLES privilege. when you use a db_link, you are connecting to the remote db with the user defined in the link, and .. on that db .. you will have the privileges of the user defined in the db link. Exactly as if you had used sqlplus to connect to that db with that user.

Maybe you are looking for

  • Payment Program - Generate additional clearing documents

    Hi. When executing an FPY1 payment run, say for a contract account. All open items that fall on the same due date are grouped into one payment document. Due to restrictions set by our reserve bank no direct debit may exceed R50000.00. For this reason

  • PLACEHOLDER COLUMN BY USING THE PARAMETER

    hi, i have to keep a place holder column in the report tiitle.what i should do? for eg:i have category column USED AS A PARAMETER WHEN I RUN THE REPORT if the CATEGORY=G i need to print the report title like GENERAL PARTY REPORT CATEGORY=C THEN CREDI

  • How do I set up multiple iCloud calendars in Outlook?

    I am trying to run to two iCloud accounts in Outlook. One is my own, private, the other is a shared account for my family. The shared family account is mainly used for calendaring (shared family calendar). I have set up my private account using iClou

  • Display multiple rows of datas from database in IDM forms

    Hi, I asked the same question in this forum before and some one answered to use 'FieldLoop'.I tried using that it didn't work.I using IDM version 5. Heres the code... EmployeeList is a supposed to be java array which contains java bean object,( Emplo

  • Keeps Ejecting PC Disk & Apps Sometimes Cover Desktop on Launchpad

    Hi. I'm loving OS X Lion and I like the gesture to bring up Launchpad and I can't wait for all apps to have fullscreen abilities so you could just swipe between apps. I still believe the gestures that Lion replaced specifically the reverse scrolling