Simple Math in SQL Query or cfset

Calculated fields in the DB vs <cfset>?
It would seem simple, but:
ACCESS DB ;>(
CF9
IIS
<cfquery name="get_total" datasource="#Request.BaseDSN#">
SELECT SUM((current_charge+penalty)-credit) AS total
FROM moorings
WHERE mooring_ID = #URL.mooring_ID#
</cfquery>
<cfdump var="#total#"> 
Variable TOTAL is undefined?
or
<cfset subtotal = current_charge+penalty>
<cfset total = subtotal-credit>
Variable CURRENT_CHARGE is undefined?
Missing ',", (, #'s?
Thanks

Run the query without using SUM to see what values are stored in the database:
<cfquery name="get_total" datasource="#Request.BaseDSN#">
SELECT current_charge, penalty, credit
FROM moorings
WHERE mooring_ID = #URL.mooring_ID#
</cfquery>
<cfoutput>
charge: #get_total.current_charge#<br />
penalty: #get_total.penalty#<br />
credit: #get_total.credit#<br />
</cfoutput>
or
<cfdump var="#get_total#">
Also, it's a good idea to get into the habit of using cfqueryparam in your SQL queries. It helps sanitize your inputs and prevents SQL injection attacks:
<cfquery name="get_total" datasource="#Request.BaseDSN#">
SELECT current_charge, penalty, credit
FROM moorings
WHERE mooring_ID = <cfqueryparam value="#URL.mooring_ID#" cfsqltype="cf_sql_integer">
</cfquery>

Similar Messages

  • Simpler reprsentation to SQL Query is needed

    Hi all,
    I have this SQL Query working goon on the Database but have some errors with Form developer so can anybody simplify it?
         SELECT *
                 FROM (SELECT   COUNT (returned_goods.ID) AS "Max Occurence", products.Name
                           FROM Returned_Goods
                           JOIN Products
                           ON returned_goods.productId = products.Id
                           GROUP BY returned_goods.productId, products.Name
                           ORDER BY COUNT (returned_goods.ID) DESC)
            WHERE ROWNUM = 1;btw, the error encounter me in Forms appears here if anybody can help: [SQL Code not working in Forms Developer without Functions|http://forums.oracle.com/forums/thread.jspa?threadID=842122&tstart=0]
    Thanks in advance :)

    The simpler SQL Staement is
    SELECT *
      FROM (SELECT   COUNT (returned_goods.ID) AS "Max Occurence", products.Name
      FROM returned_goods, products
         WHERE
         Returned_Goods.ProductId = Products.id
             GROUP BY returned_goods.productId, products.Name
             ORDER BY COUNT (returned_goods.ID) DESC)
    WHERE ROWNUM = 1;

  • Simple help in sql query

    can some one help me in Rewriting a query which i am just confused with the syntax
    SELECT DISTINCT
                   sypro.code ,
                   sypro.usage,
    sypro.user_create,
    sypro.user_modif,
    aprol.description,
                   sypro.VALUE,
                   TO_CHAR(sypro.modif_dttm,'dd/mm/yyyy') Changed_Date,
                   sypro.create_dttm Created_Date,
                   sypro.archv_flag
                   FROM system_profiles sypro, application_roles aprol          
    WHERE sypro.APROL_REFNO = aprol.APROL_REFNO
    AND sypro.modif_dttm>=TO_DATE('01/05/2006','dd/mm/yyyy')
    AND sypro.CREATE_DTTM >=('01/05/2006','dd/mm/yyyy')
    AND sypro.modif_dttm< TO_DATE('20/06/2006','dd/mm/yyyy') +1
    AND sypro.create_dttm < to_date('20/06/2006','dd/mm/yyyy')+1
    AND NVL(sypro.archv_flag , 'N') = 'N'
    ORA-01797 the error msg is --this this operator is followed by any or all                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    Sorry for bothering all just found the error ....
    thanks all

  • Problem using alias field names in a sql query

    Hello,
    I have a question regarding a simple Oracle database SQL query writeup:
    In the following (badly written but properly working) SQL query:
    Query 1:
    select
    soe.field1,
    (soe.field2 + soe.field3) as field4,
    (soe.field5 - (soe.field2 + soe.field3)) as field6,
    (select comp.parValue*soe.field7
    from
    CompTable comp) as parValue,
    (select soe.field8 - (comp.parValue*soe.field7+ soe.field9)
    from
    CompTable comp) as field10
    from
    SomeTable soe
    PROBLEM 1:
    I am re writing the code (soe.field2 + soe.field3) to get the alias field4 or column name field4 that I have created on the fly in the previously for use with the following fields. Can't I rewrite the query as follows. There is something simple missing!
    Query 2:
    select
    soe.field1,
    (soe.field2 + soe.field3) as field4,
    soe.field5 - field4 as field6, <<< field4 does not work here
    (select
    comp.parValue*soe.field7
    from
    CompTable comp) as parValue,
    (select
    soe.field8 - (comp.parValue*soe.field7+ soe.field9)
    from
    CompTable comp) as field10
    from
    SomeTable soe
    PROBLEM 2:
    Similar to the above problem, I was thinking to get a field parValue out of the CompTable table and re-use many times rather than the code shown in Query 1:
    Query 3:
    select
    soe.field1,
    (soe.field2 + soe.field3) as field4,
    soe.field5 - field4 as field6,
    soe.field7* (select comp.parValue from CompTable comp) as parValue1,
    soe.field8 - (parValue1*soe.field7+ soe.field9) as field10      <<<< parvalue1 does not work here
    parValue1*soe.field9 as TaxCondition               <<<< parvalue1 does not work here
    from
    SomeTable soe
    See that the query becomes so simple, but the above query does not work. There is something fundamentally wrong in my usage of the alias field names in creating other fields. The Query1 seems to be the only working option but its very slow as I am redoing and re-writing the whole code again and again to get the parValue field out of the CompTable table for use to create many other fields.
    I will appreciate if you can guide me in the right direction on this issue.
    Thanks and Regards
    Rama

    SELECT tmp.contract_no, tmp.Actual, tmp.Actual - tmp.NbHours
    FROM ( SELECT t.contract_no, sum(l.hrs) AS Actual, (c.labour_hours * c.labour_progress_per) / 100 AS NbHours
    FROM TASK_DELEGATION t
    INNER JOIN COST_CODE c
    ON t.cost_code = c.cost_code AND t.contract_no = c.contract_no AND t.is_inactive=0
    INNER JOIN Labour.dbo.LABOURALLOT l
    ON l.contractNo = c.contract_no AND l.costcode = c.cost_code AND l.pm = 'N'
    GROUP BY t.contract_no, c.labour_hours, c.labour_progress_per
    ) tmp

  • Simple SQL query SQL developer takes it, The wizzard of XE does not

    Hello everybody
    I wrote this simple query which SQL developer runs fine, but when I try to launch a Report based on this sql query it tells me invalid sql statement. That is true, it may be invalid because this IF clause in there..but SQL developer seems to be very tolerant or understands more...
    the reason I wrote that is because obviously if there are no bosses, ie = 0 then i would get an error when dividing it by 0, so I put that 0 just to select the good ones
    if count (bosses) >0
    select company, postcode,
    sum( bosses/staff)
    from evaluation
    group by company, postcode
    Thank you very much
    Alvaro

    oh yes (blushed in shame as how dumb i looked like) i knew about the denominator 0 and infinite as as result i just didnt notice my zero was on the numerator :(
    however, i run the query and i got this message in sql developer
    Error starting at line 1 in command:
    select company, postcode,
    case when staff != 0 then sum( bosses/staff) end
    from evaluation
    group by company, postcode
    Error at Command Line:2 Column:10
    Error report:
    SQL Error: ORA-00979: not a GROUP BY expression
    00979. 00000 - "not a GROUP BY expression"
    *Cause:   
    *Action:                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Simple SQL Query and Parameters and LOV

    Newbie and trying to work thru building a simple sql query with a single table query and use a parameter and lov.
    Can anyone point me to an example.
    simple query:
    select cust_id, name_desc, name_add1, name_add2, name_city
    from customer_table
    where cust_id = :cust_parm
    This works in straight sql and in the query builder by prompting for the customer ID. When building a parameter using LOV or search, it doesn't seem to detect the variable.
    Thanks..
    DD

    If you are using version 11g, then as soon as you save the query in the data model, it should notice the parameter and ask if you want to add the parameter to the data model. What version of BIP are you using?
    What happens if you exclude the parameter from the query and simply hard-code the criteria? Can you generate XML data?
    From your wording, it sounds like you're trying to create a parameter from the LOV dialog. LOVs and parameters are totally distinct. After each are created separately, then you configure the parameter to use the LOV.

  • Simple SQL query statement is needed

    I need a simple SQL query to fetch records which is existed in all the departments.
    for example: i want to list the employees which are existed in each and every department.. not sure how should i get those.. will anyone help me please.. thanks in advance

    I think it would be wise to go to the following training:
    Oracle Database <version> : Introduction to SQL
    You will get the information you are looking for in five days. You can go find a tutorial on ANSI SQL, as advised by this board for free, to fix your immediate problem with a simple query. But, I personally recommend a more formal class specific to Oracle, as you will also get information about PL/SQL, and you get the benefit with working with other DBA/programmers when you are learning. This will solve your immediate issue, and any future issues with the language.
    You can find it in the Education section of the Oracle website.

  • Is there a simple way to refresh a SQL Query (Updatable report) region

    I have a page in APex 4.1 that has many regions. I would like to be able to refresh a single region.
    Currently, I have the following
    Region (sql query updateable report).
    STATIC ID = LANDINGS
    in the region footer, I have:
    <script type="text/javascript">
    $s('P110_LANDINGS_REGION_ID','#REGION_STATIC_ID#');
    </script>
    P110_LANDINGS_REGION_ID is a hidden field.
    I use javascript to refresh....but it does not seem to be working. Previously, we had hard-coded the region id ( $a_report('1363338167540162011','1','100','100');) ...but that ID was somehow corrupted, which has lead me to the 'OMG...there must be an easier way!' lament.
    the javascript is:
    $a_report('P110_LANDINGS_REGION_ID','1','100','100');
    thanks!
    Karen
    ps. could I just directly reference the static id in my javascript...
    $a_report('LANDINGS','1','100','100');

    Karen,
    First off: please post code in &#123;code&#125;...&#123;code&#125; tags!
    function AddFavoriteSpecies()
    get = new htmldb_Get(null,&APP_ID.,'APPLICATION_PROCESS=favorite_species_collection',0);
    gReturn = get.get();
    rowCount = rowCount + parseInt(gReturn);
    pHMS_add = '&G_HMS_FLAG.';
    $a_report('1363338167540162011','1','100','100');
    //$a_report($x('P110_LANDINGS_ID').value,'1','15','15');the statement:
    $a_report('1363338167540162011','1','100','100'); works, but the statement $a_report($x('P110_LANDINGS_ID').value,'1','15','15'); does not.
    Can anyone help.
    I am assigning the page field P110_LANDINGS_ID in the footer of a region with a static id = LANDINGS.
    <script type="text/javascript">
    $s('P110_LANDINGS_ID','#REGION_STATIC_ID#');
    </script>
    Well, let's start by dumping $a_report. This is undocumented code, and it has long been replaced by triggering a refresh.
    Next, don't use $x(pNode).value to retrieve a value. Rather use $v(pNode) to do this.
    function AddFavoriteSpecies()
       get = new htmldb_Get(null,&APP_ID.,'APPLICATION_PROCESS=favorite_species_collection',0);
       gReturn = get.get();
       rowCount = rowCount + parseInt(gReturn);
       pHMS_add = '&G_HMS_FLAG.';
       //get the region id from the item
       //use it in a jQuery selector to get the region
       //trigger the refresh event on this object
       $("#" + $v('P110_LANDINGS_ID')).trigger('apexrefresh');
    }Now if you want to make sure that P110_LANDINGS_ID contains a value, add an alert with its value before you use it.
    alert('P110_LANDINGS_ID value: '+$v('P110_LANDINGS_ID'))

  • A simple SQL query question

    I have an interesting problem and wondering how I can get this result in a single SQL query:
    Here is table emp has data with a row for every year since the employee joined with the salary paid that particular year with following columns:
    emp (
    id varchar2(10),
    name varchar2(25),
    interested_year date,
    salarypaid number(10)
    I would like to print the results as follows:
    id name previousyear_salarypaid currentyear_salarypaid
    x xxxxx xxxxxx xxxxx
    Is this possible to do? I have tried to simplify my actual problem so I hope I have included all necessary details.

    Just to clarify, the columns mentioned in the results are
    previousyear_salarypaid is nothing but
    salarypaid where interested_year = '2007'
    currentyear_salarypaid is nothing but
    salarypaid where interested_year = '2006'

  • SQL query difficulties

    Hello, I am trying to create an SQL query to join some tables but I can't get it right so I'm hoping I can get some help here-it's for a college assignment and the deadline is looming.I realise that this is a JDBC forum but I'm getting desperate....
    I've got two tables-one with student details (name,address etc etc) and another one containing the information on the subjects that each one is taking.It is only composed of two fields-studentID which is the foreign key to the first table and another called subject which shows a subject taken by the student.
    Natually one student can take several subjects so a slice of the table would be something like
    studentid subject
    1 history
    1 geography
    1 art
    2 maths
    2 history
    2 geography
    3 physics
    3 history
    etc etc
    What I want to do is have a query where one can see the names of the students(in the studentDetails table) that take a particular combination of subjects.For example I would like a query that could tell me which students take BOTH history and geography.(1 & 2 but not 3 in the example above). I realise that this must be a relatively simple query but I don't have much experience with SQL queries.
    Any help would be greatly,greatly appreciated
    Thanks.

    A few databases don't support sub-selects (the 2nd variant) and a few will be fussy about how you alias, or reference a column from an aliased table, but most decent DBs will give a meaningful enough error message that you can work that out...
    I can't think of any possible JDBC issues.
    The only other thing is that joins always have some performance implications; how you do them and what is indexed can make a big difference. In particular, your student_id probably ought to be a primary key in STUDENTS and an indexed column in the other table... Whether or not an index on subject will improve performance depends on the data distrubution and the database...

  • Discoverer Report showing Null VS Show SQL query showing results !!!

    I created a simple Cross Tab Discoverer report from a custom SQL which has a calculation for balances. The output is giving all null values even though there are balances. The output doesn't seem right. So I copied the query from Tools-->Show SQL and ran the query in the TOAD where I'm showing balances for the report. I don't understand why it is not showing in the discoverer. Please help.
    Thanks
    Edited by: PA1B on Jan 27, 2010 11:40 AM

    Sorry for late reply.
    Below is the Show SQL query. I don't think the query is application dependent. C_1 is my calculation.
    SELECT o279709.SEGMENT3 as E279727,
    o279709.SEGMENT4 as E279728,
    CASE WHEN o279709.CURRENCY_CODE = 'USD' AND o279709.TRANSLATED_FLAG <> 'Y' THEN SUM(o279709.ENDING_BAL) ELSE 0 END as C_1,
    GROUPING_ID(o279709.CURRENCY_CODE,o279709.SEGMENT3,o279709.SEGMENT4,o279709.TRANSLATED_FLAG) as GID
    FROM ( --Foriegn Entity USD Balances
    SELECT                B.SEGMENT1,
                                       B.SEGMENT2,     
                                       B.SEGMENT3,
                                  (select distinct substr(cat.COMPILED_VALUE_ATTRIBUTES,5,1) from apps.fnd_flex_values cat
                   where FLEX_VALUE_SET_ID = (select bat.FLEX_VALUE_SET_ID from apps.fnd_id_flex_structures_vl aat, apps.fnd_id_flex_segments_vl bat
                                                                                                                       where bat.id_flex_code = 'GL#' and
                                                                                                                            bat.id_flex_code = aat.id_flex_code and
                                                                                                                            aat.APPLICATION_ID = bat.APPLICATION_ID and
                                                                                                                            aat.APPLICATION_ID = 101 and
                                                                                                                            bat.SEGMENT_NAME = 'Prime Account' and
                                                                                                                            aat.id_flex_num = bat.id_flex_num
                                                                                                                            and bat.id_flex_num in (select distinct chart_of_accounts_id from apps.gl_code_combinations gat
                                                                                                                                                                              where gat.code_combination_id = A.code_combination_id))
                                       and cat.flex_value = b.segment3) ACCT_TYPE ,
                                       B.SEGMENT4,
                                       B.SEGMENT5,
                                       B.SEGMENT6,
                                       B.SEGMENT7,
                                       B.SEGMENT8,
                                       B.SEGMENT9,
                                       B.SEGMENT10,
                                       B.SEGMENT11,
                                       B.SEGMENT12,
                                       B.SEGMENT13,
                                       C.NAME,
    A.SET_OF_BOOKS_ID,
                                       A.CURRENCY_CODE,A.TRANSLATED_FLAG,
                                  SUM(NVL(A.BEGIN_BALANCE_DR,0) - NVL(A.BEGIN_BALANCE_CR,0)) BEG_BAL,
                                  SUM(NVL(A.PERIOD_NET_DR,0)) DEBITS,
    SUM( NVL(A.PERIOD_NET_CR,0)) CREDITS ,
    A.PERIOD_NAME,
                                  SUM(NVL(A.BEGIN_BALANCE_DR,0) - NVL(A.BEGIN_BALANCE_CR,0))+ SUM(NVL(A.PERIOD_NET_DR,0) - NVL(A.PERIOD_NET_CR,0)) ENDING_BAL
    FROM                     APPS.GL_BALANCES A ,
                                       APPS.GL_CODE_COMBINATIONS B,
                                       APPS.GL_SETS_OF_BOOKS     C
    WHERE                     A.CODE_COMBINATION_ID = B.CODE_COMBINATION_ID
    --AND                           A.PERIOD_NAME = 'SEP-09'
    AND                          C.SET_OF_BOOKS_ID = A.SET_OF_BOOKS_ID
    --AND                           A.TRANSLATED_FLAG <> 'Y'
    --AND                           B.SEGMENT1 = '83101'
    --AND                           B.SEGMENT3 = '14602'
    --AND                           A.SET_OF_BOOKS_ID = 77
    --AND                           A.CURRENCY_CODE = 'USD'
    GROUP BY           A.CODE_COMBINATION_ID,
                                  B.SEGMENT1,
                                       B.SEGMENT2,     
                                       B.SEGMENT3,
                                       B.SEGMENT4,
                                       B.SEGMENT5,
                                       B.SEGMENT6,
                                       B.SEGMENT7,
                                       B.SEGMENT8,
                                       B.SEGMENT9,
                                       B.SEGMENT10,
                                       B.SEGMENT11,
                                       B.SEGMENT12,
                                       B.SEGMENT13,          
                                       A.CURRENCY_CODE,
                                       A.TRANSLATED_FLAG,
                                       C.NAME,A.PERIOD_NAME,
    A.SET_OF_BOOKS_ID
    ) o279709
    WHERE (o279709.PERIOD_NAME = 'DEC-09')
    AND (o279709.SET_OF_BOOKS_ID <> 72)
    AND (o279709.SEGMENT12 = '000')
    AND (o279709.SEGMENT3 IN ('10101','10301','10502','12001'))
    AND (o279709.SEGMENT1 IN ('82901','82902','82903','83001','83003','83201'))
    GROUP BY GROUPING SETS(( o279709.CURRENCY_CODE,o279709.SEGMENT3,o279709.SEGMENT4,o279709.TRANSLATED_FLAG ),( o279709.SEGMENT3,o279709.SEGMENT4 ),( o279709.SEGMENT3 ))
    HAVING (GROUP_ID()=0)
    ORDER BY GID DESC;
    Thanks,
    PA1
    Edited by: PA1B on Jan 29, 2010 12:50 PM

  • SQL Query Help Needed

    I'm having trouble with an SQL query. I've created a simple logon page wherein a user will enter their user name and password. The program will look in an Access database for the user name, sort it by Date/Time modified, and check to see if their password matches the most recent password. Unfortunately, the query returns no results. I'm absolutely certain that I'm doing the query correctly (I've imported it directly from my old VB6 code). Something simple is eluding me. Any help would be appreciated.
    private void LogOn() {
    //make sure that the user name/password is valid, then load the main menu
    try {
    //open the database connection
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection con = DriverManager.getConnection("jdbc:odbc:LawOffice2000", "", "");
    Statement select = con.createStatement();
    String strTemp = "Select * From EMPLOYEES Where INITIALS = '" + txtUserName.getText() + "' Order By DATE Desc, TIME Desc";
    ResultSet result = select.executeQuery(strTemp);
    while(result.next()) {
    if (txtPassword.getPassword().toString() == result.getString("Password")) {
    MenuMain.main();
    else {
    System.out.println("Password Bad");
    System.out.println(txtUserName.getText());
    System.out.println(result.getString("Password"));
    break; //exit loop
    //close the connection
    con.close(); }
    catch (Exception e) {
    System.out.println("LawOfficeSuite_LogOn: " + e);
    return; }
    }

    The problem is here: "txtPassword.getPassword().toString() == result.getString("Password"))"
    Don't confuse String's equals() method with the equality operator '=='. The == operator checks that two references refer to the same object. If you want to compare the contents of Strings (whether two strings contain the same characters), use equals(), e.g. if (str1.equals(str2))...
    Example:String s1 = "foo";
    String s2 = new String("foo");
    System.out.println("s1 == s2: " + (s1 == s2)); // false
    System.out.println("s1.equals(s2): " + (s1.equals(s2))); // trueFor more information, check out Comparison operators: equals() versus ==

  • How to run a sql query from a button in apex 3.0

    Hi,
    I am brand new and went through/installed the obe project tracker. I have need to create a simple application that displays a result (2 fields, name and license number) based on two parameters (dob and login id) which all are stored in 1 table in the database. I could this very simply in VB or VB.net but have no idea how to do it in apex.
    Please provide guidance,
    Thank you,
    Tom

    Hi Tom,
    Sounds like a report region will satisfy your requirements.
    Create a new report region on one of your pages.
    Choose SQL Report and give the region a title.
    When you get to the "Enter SQL Query or PL/SQL function returning a SQL Query:" step, type:
    SELECT name, license_number
    FROM   <insert_your_table_name_here>
    WHERE  dob = :P<n>_dob
    AND    login_id = :P<n>loginid(replace <n> with the page number that the region is on and use your own table name).
    Don't try to run the page yet - it will give 'No data found'
    Now, go back to the Page Definition screen and add two items in the region you just created - call them P<n>dob and P<n>login_id
    Then, create a button in the same region (to be displayed amongst the region's items) - call it P<n>_GO and click 'Create' (take all the other defaults).
    Now you can run the page, put some values into the fields and click go.
    If you want to get fancier, you can change the text items to select lists etc. - let us know if you need help with that.
    Hope this helps,
    Bryan.

  • No Data Found for SQL query

    Hello,
    I have a simple SQL query in a report.
    select
          null as "Complete",
             a.col1,
             a.col2,
             a.col3,
             a.col4,
          b.col2
    from      TableA a, TableB b
    where   a.id = b.idThere is a known issue in apex 4.0 that is causing the "When No Data Found" message to work incorrectly so that this is returned:
    report error:
    ORA-01403: no data found
    Is there a way to return a message in a SQL statement? If not, any suggestions on how I can convert this in the existing report to PL/SQL would be appreciated.
    Thanks!
    Matt

    I would like to do something similar to this (below) but the only option that is given other than "SQL Query" is “PL/SQL function body returning a SQL query”
    I'm not sure how to do this as a funciton.
    declare
    vComplete Varchar2;
    vCol1        Varchar2;
    vCol2        Varchar2;
    vCol3        Varchar2;
    vCol4        Varchar2;
    vColB2      Varchar2;
    Begin
    select
             null as "Complete",
             a.col1,
             a.col2,
             a.col3,
             a.col4,
             b.col2
    into vComplete,vCol1,vCol2,vCol3,vCol4,vColB2
    from   TableA a, TableB b
    where   a.id = b.id
    Dbms_output.put_line(vComplete,vCol1,vCol2,vCol3,vCol4,vColB2);
    Exception
          When no_data_found
                Dbms_output.put_line(vComplete,vCol1,vCol2,vCol3,vCol4,vColB2);
          When others
                Dbms_output.put_line(‘exception handling message’);
    End;

  • SQL query with "parameters"

    Hi,
    I want a sql query as follows (but it seems not be as simple as that...)
    select A1, A2,
    select sum(B3)
    from B1 = A2
    where
    from A
    where A1 = '1001'
    is it possible, in some way, to have A2 from outer select statement as a parameter to inner select statement?

    Hi,
    user8819407 wrote:
    Hi,
    I want a sql query as follows (but it seems not be as simple as that...)
    select A1, A2,
    select sum(B3)
    from B1 = A2
    where
    from A
    where A1 = '1001'
    is it possible, in some way, to have A2 from outer select statement as a parameter to inner select statement?Yes, you can reference columns from a parent query within its child query.
    For example:
    select  A1, A2,
             select  sum (b.B3)
             from   b
             where  b.B1 = a.A2
    from     A
    where     A1 = '1001'
    ;Within the sub-query, you don't have to qualify columns from b; that is, b3 is assumed to mean b.b3. If the column name is unique, you don't have to qualify columns from table a, either. That is, if b does not have a column called a2, then a2 in the sub-query could only mean a.a2, and Oracle doesn't make you spell out which table a2 comes from, but it makes the code a lot easier to understand and debug if you do qualify the columns.
    By the way, a sub-query that references its parent query like this is called a Correlated Sub-Query .
    "Parameter" doesn't really apply to this situation.

Maybe you are looking for