Executing nested query contains ORDER BY:Help Needed

I have a database in ORACLE 8.0 enterprise
edition in HP-UX. I am trying to execute the following query
"select * from ( select * from temptable order by value desc) where rownum < 5"
and I am getting the following error
"missing right parenthesis"
This syntax is given in the Oracle user guide
under sql commands section and it is not
working.
Similar query is working on Oracle 8.1 running on Win NT.
Does any body throw some light.
Thanks in advance
-raj

Your query works fine in Oracle 8i:
SELECT *
FROM (SELECT *
FROM temptable
ORDER BY value DESC)
WHERE ROWNUM < 5;
However, prior to Oracle 8i, in Oracle 8.0, it is not allowed to have an ORDER BY clause within a nested query. So, in Oracle 8.0, a query like the above cannot work. However, the following, with the ORDER BY clause in the outer query will work:
SELECT *
FROM temptable a
WHERE 5 >=
(SELECT COUNT (*) + 1
FROM temptable b
WHERE b.value > a.value)
ORDER BY a.value DESC;
null

Similar Messages

  • SQL Query Sorting Order issue - Help needed

    Hi All,
    I am using the following query in my project to display the records in the grid.
    /* Formatted on 04-09-2013 PM 8:01:51 (QP5 v5.149.1003.31008) */
      SELECT eol,
             status_msg,
             relation,
             building_name,
             device_id id,
             CEIL (SYSDATE - updated_date) duration,
             lab_id,
             aisle_id,
             aisle_location_id,
             ip_address,
             port,
             slot_num,
             hostname,
             pid,
             description,
             sl_num,
             eitms_code,
             status,
             dnd_flag,
             aisle,
             aisle_location,
             spname,
             os_version,
             user_id,
             TO_CHAR (updated_date, 'YYYY-MM-DD HH24:MI:SS') updated_date,
             isterm_svr,
             net_type,
             DEVICE_GROUP_REF,
             cmd_id_ref,
             LISTAGG (TESTBED_ID, ',') WITHIN GROUP (ORDER BY TESTBED_ID)
                AS testbeds_id_ref,
             LISTAGG (NAME, ',') WITHIN GROUP (ORDER BY TESTBED_ID)
                AS testbeds_names,
             spname || '-' || ip_address || '-' || port AS child_asset_group
        FROM DEVICE_TESTBED_VW
       WHERE lab_id IN
                ('7099849',
                 '10769617',
                 '4258712',
                 '10513562',
                 '10515074',
                 '5882676',
                 '8330925')
    GROUP BY eol,
             status_msg,
             relation,
             device_id,
             lab_id,
             aisle_id,
             aisle_location_id,
             ip_address,
             port,
             slot_num,
             hostname,
             pid,
             description,
             sl_num,
             eitms_code,
             status,
             dnd_flag,
             aisle,
             aisle_location,
             spname,
             os_version,
             user_id,
             updated_date,
             isterm_svr,
             net_type,
             DEVICE_GROUP_REF,
             cmd_id_ref,
             building_name
    ORDER BY building_name ASC,
             LOWER (child_asset_group) ASC,
             LOWER (relation) DESC
    The problem is , if any one sorting with any column  , the order is not correct
    In this below code , i have done sorting by port . But the result data order is not correct .
    /* Formatted on 04-09-2013 PM 8:07:02 (QP5 v5.149.1003.31008) */
      SELECT eol,
             status_msg,
             relation,
             building_name,
             device_id id,
             CEIL (SYSDATE - updated_date) duration,
             lab_id,
             aisle_id,
             aisle_location_id,
             ip_address,
             port,
             slot_num,
             hostname,
             pid,
             description,
             sl_num,
             eitms_code,
             status,
             dnd_flag,
             aisle,
             aisle_location,
             spname,
             os_version,
             user_id,
             TO_CHAR (updated_date, 'YYYY-MM-DD HH24:MI:SS') updated_date,
             isterm_svr,
             net_type,
             DEVICE_GROUP_REF,
             cmd_id_ref,
             LISTAGG (TESTBED_ID, ',') WITHIN GROUP (ORDER BY TESTBED_ID)
                AS testbeds_id_ref,
             LISTAGG (NAME, ',') WITHIN GROUP (ORDER BY TESTBED_ID)
                AS testbeds_names,
             spname || '-' || ip_address || '-' || port AS child_asset_group
        FROM DEVICE_TESTBED_VW
       WHERE lab_id IN
                ('7099849',
                 '10769617',
                 '4258712',
                 '10513562',
                 '10515074',
                 '5882676',
                 '8330925')
    GROUP BY eol,
             status_msg,
             relation,
             device_id,
             lab_id,
             aisle_id,
             aisle_location_id,
             ip_address,
             port,
             slot_num,
             hostname,
             pid,
             description,
             sl_num,
             eitms_code,
             status,
             dnd_flag,
             aisle,
             aisle_location,
             spname,
             os_version,
             user_id,
             updated_date,
             isterm_svr,
             net_type,
             DEVICE_GROUP_REF,
             cmd_id_ref,
             building_name
    ORDER BY PORT ASC
    Can some one help me to fix this issue?

    Hi,
    Sorry, it's not clear what you want.
    Whenever you have a problem, please post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) from all tables involved, so that the people who want to help you can re-create the problem and test their ideas.
    Also post the results you want from that data, and an explanation of how you get those results from that data, with specific examples.
    Simplify the problem as much as possible. For example, if you really need to GROUP BY 28 columns, post a problem where you need to GROUP BY only 2 or 3 columns.  (Just explain that you really have 28, so people will give solutions that are sure to work for all 28).)
    Always say which version of Oracle you're using (for example, 11.2.0.2.0).
    See the forum FAQ: https://forums.oracle.com/message/9362002

  • GROUP BY and ORDER BY help needed

    I have got an sql query where I have the need to pull out the latest copy of duplicate info, but what is happening is that the first instance is being displayed. The query I have is this:
    SELECT *
    FROM tbl_maincontenttext
    WHERE fld_menusection = 3
    GROUP BY fld_webpage
    ORDER BY fld_timedate DESC
    Basically, I have content that is listed under menu section 3, but within that I will have several copies of content that will relate to a specific webpage (eg: about us). What is currently happening is that GROUP BY is obviously grouping the similarly named 'about us', but it is pulling the first record it comes across out of the database rather than the latest updated record.
    As you can see, I am trying to get the query to order by fld_timedate which is a CURRENT_TIMESTAMP, but it's not working!
    I'm hoping that there is some sort of SQL that I am unaware of that will help me group by and display the latest update/content.
    Thanks.
    Mat

    It would help if you could show us the table definition. Your SQL statement is ambigous because you are selecting all table columns, yet only including one column in the group by clause.  A SQL statement must contain all selected columns that are not aggregates. Most DBMS will return an error for this statement. Others that don't return an error will return unexpected results.

  • Error while running Process Order API to import orders - URGENT HELP NEEDED

    Hi all,
    I'm stuck with order import using OE_ORDER_PUB.PROCESS_ORDER api. Wanted to import a simple order in Vision database using the process order api. Figured out the right data to use, inserted into Headers and Lines Iface All tables. When calling the OE_ORDER_PUB.PROCESS_ORDER api, it is throwing this error:
    "Header ID does not exist on this record or does not match ID specified on header record. You require a valid header ID if the operation is Create."
    But when I validate the same record using the CORRECTIONS form in Order Import GUI, the order is successfully validated. Also the order is imported when I click the IMPORT button.
    I understand that HEADER_ID column is not required for creating a new order, but not sure why it is erroring. Here is the data I'm using:
    Insert into oe_headers_iface_all
    (org_id, order_type_id, order_source_id, orig_sys_document_ref, ordered_date, request_date,
    sold_from_org_id, sold_to_org_id, ship_from_org_id, ship_to_org_id, invoice_to_org_id,
    CREATED_BY,CREATION_DATE,LAST_UPDATED_BY,LAST_UPDATE_DATE,LAST_UPDATE_LOGIN,OPERATION_CODE)
    values (204, 1430, 1046, '101040', sysdate, sysdate, 204, 1004, 606, 1018, 1017, 0, sysdate, 0, sysdate, 0, 'CREATE');
    Insert into oe_lines_iface_all
    ("ORDER_SOURCE_ID","ORIG_SYS_DOCUMENT_REF","ORIG_SYS_LINE_REF","ORIG_SYS_SHIPMENT_REF","ORG_ID","INVENTORY_ITEM","LINE_TYPE_ID",request_date,"SCHEDULE_DATE","DELIVERY_LEAD_TIME","ORDERED_QUANTITY","ORDER_QUANTITY_UOM",sold_from_org_id, sold_to_org_id, ship_from_org_id, ship_to_org_id, invoice_to_org_id,"UNIT_SELLING_PRICE","CREATED_BY","CREATION_DATE","LAST_UPDATED_BY","LAST_UPDATE_DATE","LAST_UPDATE_LOGIN","OPERATION_CODE")
    values
    (1046,'101040', '1', '1', 204, 'AS72111', 1427, sysdate, sysdate+1, 0, 10, 'Ea' ,204, 1004, 606, 1018, 1017,100,0,sysdate,0,sysdate,0,'CREATE');
    Any help is appreciated.
    FYI - this is a 11.5.10.2 version installed on Windows 2003 server.
    Thanks in advance.
    Jags

    I might be late in replying, but hope it might help.
    From your query it seems you are inserting records into interface tables and then calling process order API( probably from some PL/SQL block).
    This is where I am confused, because I hope you understand, that interface tables are for use with Order Import concurrent Program, and for Process ORder API, you need to provide the data as parameter. The api has, header record type and line table type as parameters. So you need to assign correct data to these variables and pass them as parameter when you are calling Process Order API.
    If you are doing the same thing, then post the exact pl/SQL code and error message from the API. That might help diagnose the issue.
    Regards,
    Nitin Darji

  • JPQL Query for specific usecase, help needed

    Does anyone knows how to write the JPQL query for this specific use case.
    Take 3 tables,
    Table 1 contains bids for many auctions (Bid table)
    Table 2 Contains many auctions (Auction Table)
    Table 3 contains many users (User Table)
    I need a query to retrieve all the highest bids per auction for a particular user.
    For example if the user has bidded on 10 auctions., but for each auctions has placed 3 bids each. Following the query, I would expect to get 10 bids back, each being the highest per auction.
    A Bid has a bid value that can be used for filtering.
    Thanks
    Peter

    It would be something like the JPQL version of 'select * from bids join auctions using (auction_id) where bids.userid = ? group by auctions.auction_id order by bids.amount desc'. But this is primarily an SQL question, and only secondarily a question as to how to translate that into JPQL, which should be straightforward.

  • Purchase order report -help needed.

    Hi guys,
    Can anyone help me create a report for the purchase orders (similar to ME2N) ,my company needs all the info related to a PO like payment history.we need to pull all <b>closed POs</b> during a certain time period.Is ther a way todo this .
    I'd appreciate your help.'
    Thanks
    Cheris T

    Hello,
    You will need to run both ME80N and FBL1N. ME80FN can display PO history and from FBL1N you can get payment history.
    Hope this helps !
    Cheers !

  • Sales Order - Export help needed

    Hi Gurus
    I am checking Export Sales Order Settings and also testing export sales order.
    While creating sales order I am getting one error "Material SDHD00000A4A0501 is not defined for sales org.1200, distr.chan.00,  language EN"
    Kindly give me the details steps to check the settings for export.
    Rajesh

    Hi
    You have to extend the material to the 1200 - 00 (S.O and DC) and the language EN can be maintained in the Additional Data (tab on the application tool bar) in the material master.
    Thanks,
    Ravi

  • Query using Group by - help needed

    I am having a query as follows:
    select id_nbr, stop_nbr, street || city || state, count(sub_stop_nbr)
    from details where created_date = ' 22-Jul-08';
    As group by clause is missing it is giving errors.
    But when I add group by to this query, I have to add all selected values.
    How can I add the concatenatd values here.
    Is there any other way rather than writing as :
    (select id_nbr, stop_nbr, street || city || state, count(sub_stop_nbr)
    from details where created_date = ' 22-Jul-08'
    group by id_nbr, stop_nbr, street || city || state)

    so where is the problem in writing:
    select id_nbr, stop_nbr, street || city || state, count(sub_stop_nbr)
    from details
    where created_date = ' 22-Jul-08'
    group by id_nbr, stop_nbr, street || city || state
    ????

  • FLASHBACK QUERY - Range based - Doubt - Help needed -URGENT

    Hi,
    I want to user the flashback query facility to capture the history of versions for a day (i.e) i want to get the data versions from morning 10 a.m to 6.pm.
    How to get the versions by using the time range for a day.
    I used the query as
    select a.eno,
              b.eno,
              a.ename,
              b.ename
    from emp a, emp as of timestamp
    to_timestamp('08-NOV-2006 06:32:21.999999 AM','DD-MON-RRRR HH:MI:SS.ff6 AM') b
    where a.eno=b.eno
    The above query will fetch only one versions for the specified timestamp.
    How could i implement the range based search through flashback query.
    Please suggest any methods to implement the same.
    Thanks in advance.

    You'll want to read the documentation about Oracle Flashback Version Query.<br><br>
    Regards,
    Rob.

  • Executing BI Query in Background !!!

    Hi Experts,
    I want to execute my BI query in Back ground, as it contains lots of data, it is taking lots of lots of time for direct execution, I tried APD, but it seems doesnt work for back grnd procss, tried FM RRW3_GET_QUERY_VIEW_DATA., but dont know how to pass variables for it.
    My query contains variables also, Help is needed urgently please !!!
    Thanks.

    Hi
    Please check these links
    Execute BW query using ABAP Part I
    /people/durairaj.athavanraja/blog/2005/04/03/execute-bw-query-using-abap-part-i
    Execute BW query using ABAP Part II
    /people/durairaj.athavanraja/blog/2005/04/03/execute-bw-query-using-abap-part-ii
    and can you please tell me the parameters which you need to pass???
    Best Regards
    Rohit

  • Problem executing the Query.

    Hi,
    When I am trying to open a Query in the Query Designer I am getting the error, like
    Error Characteristic BP in Ext.Sys (BPCo) must be uniquely selected in the query
    Error Characteristic BP in Ext.Sys (BPEmp) must be uniquely selected in the query
    Error Characteristic BP in Ext.Sys (BP R) must be uniquely selected in the query
    Error Characteristic BP in Ext.Sys (BP-P) must be uniquely selected in the query
    Error Characteristic BP in Ext.Sys (BPSh-P) must be uniquely selected in the query
    Error Characteristic BP in Ext.Sys (BPSldTo) must be uniquely selected in the query
    Error Characteristic BP in Ext.Sys (BPSrvEm) must be uniquely selected in the query
    Error Characteristic BP in Ext.Sys (BPR) must be uniquely selected in the query
    It may be due to a characteristic 0BP_EXTERN- Previous Account Number which is a Navigation Attribute of all these characteristics,
    *0CRM_SOLDTO, 0CRM_SHIPTO, 0CRM_BILLTO, etc etc.  So all these characteristics which are associated with 0BP_EXTERN are having some problem.
    All those Queries where 0BP_EXTERN is used are having the same issue. There used to be no issue till yesterday, I was able to execute the Query.
    Can anybody help me solving this issue??
    Thanks in advance.
    Prasapbi

    Also, when I went to InfoObject Properties,
    Business Explorer--> Selection --> "Unique for Every Cell" (this option is selected for the InfoObject 0BP_EXTERN),
    Or will it work if I select the option "No Selection Restriction".
    Thanks
    Prasapbi

  • Help needed in executing SQL query...

    Hi,
    I am very new to JDeveloper. Curently i am tryin to execute an SQL query from the BPEL process, the output of the query is to be mapped to a variable field from a target xsd file. the query is fairly simple, like
    SELECT emp
    FROM emp_table
    WHERE emp_id=123
    The target field, namely "employee", is an element from the xsd file. I tried using Java embedding activity to connect to the db and execute the query through a piece of Java code, but couldn't find a way to assign the output of the query to the field. however lately i also discovered the Database Adapter services which helps me create a database connection, but still i am not sure as of how to handle and map the output of the query to the variable field.
    Can somebody please help me in resolving the issue either through Java Embed activity or Database Adapter services??
    Thanks in advance
    Anjan

    Anjan,
    I suggest you try the [url http://forums.oracle.com/forums/forum.jspa?forumID=212]BPEL Forum
    John

  • Help needed in query optimization.....

    Hi
    I have this below query which automatically gets generated in siebel.
    Problem is when i execute this query in toad for "Nichole" it took 2 mins to return 30 records but when i execute this same query for "Adam" it returns more records than Nichole and return results in 1-2 secs. i Know executing query in toad is not a proper way but this below query will get executed in same way thru siebel application. Histogram is already created on column "Name" but of no help. Composite Index(CX_AA_EVNT_RADIO_BATCH_TIME) is there on column bot_id & timestp.
    Table s_org_ext has only 5 records of "Nichole" and 10 records of "Adam".
    Will including Column "Name" in Above composite index can help?
    Please anybody can suggest me anything in this? whatelse i can do to tune this query?
    Thanks for your help in advance
    Chandan Singh
    Also, don't know how better i can format this code :-(
    SELECT t7.conflict_id, t7.last_upd, t7.created, t7.last_upd_by,
    t7.created_by, t7.modification_num, t7.row_id, t7.last_upd,
    t7.aa_acount_id, t7.aa_last_step, t7.accessory, t7.account_exists,
    t7.account_number, t7.actn_cd, t7.action_counter, t7.activated_by,
    t7.address, t7.address_2, t7.address_validation_status,
    t4.account_name, t7.aggregated_account_id, t7.aggregated_flag,
    t7.asset_id, t7.auto_delivery_type, t7.auto_make, t7.auto_model,
    t7.auto_year, t7.automated_approval, t7.activation_frequency,
    FROM siebel.s_prod_int t1,
    siebel.s_org_ext t2,
    siebel.s_asset t3,
    siebel.av_account t4,
    siebel.s_org_ext t5,
    siebel.s_prod_int_x t6,
    siebel.av_event t7
    WHERE t1.row_id = t6.par_row_id(+)
    AND t7.promotion_code = t1.part_num(+)
    AND t7.asset_id = t3.row_id(+)
    AND t3.owner_accnt_id = t5.par_row_id(+)
    AND t7.id = t2.par_row_id --- S_ORG_EXT_U3
    AND t7.id1 = t4.row_id(+)
    AND (t2.NAME = 'Nichole')
    ORDER BY t7.bot_id, t7.timestp
    Below is the execution plan for above query.
    Execution Plan
    0 SELECT STATEMENT Optimizer=CHOOSE (Cost=399904 Card=5609601 Bytes=4930839279)
    1 0 NESTED LOOPS (OUTER) (Cost=399904 Card=5609601 Bytes=4930839279)
    2 1 NESTED LOOPS (OUTER) (Cost=343808 Card=5609601 Bytes=4824256860)
    3 2 NESTED LOOPS (OUTER) (Cost=231616 Card=5609601 Bytes=4740112845)
    4 3 NESTED LOOPS (OUTER) (Cost=175520 Card=5609601 Bytes=4482071199)
    5 4 NESTED LOOPS (OUTER) (Cost=119424 Card=5609601 Bytes=4325002371)
    6 5 NESTED LOOPS (Cost=63328 Card=5609601 Bytes=4240858356)
    7 6 TABLE ACCESS (BY INDEX ROWID) OF 'av_event' (Cost=6729 Card=5659910 Bytes=4126074390)
    8 7 INDEX (FULL SCAN) OF 'av_event_timpstp' (NON-UNIQUE) (Cost=24559 Card=5659910)
    9 6 TABLE ACCESS (BY INDEX ROWID) OF 'S_ORG_EXT' (Cost=1 Card=1 Bytes=27)
    10 9 INDEX (UNIQUE SCAN) OF 'S_ORG_EXT_U3' (UNIQUE)
    11 5 TABLE ACCESS (BY INDEX ROWID) OF 'S_PROD_INT' (Cost=1 Card=1 Bytes=15)
    12 11 INDEX (RANGE SCAN) OF 'S_PROD_INT_M3' (NON-UNIQUE)
    13 4 TABLE ACCESS (BY INDEX ROWID) OF 'av_account' (Cost=1 Card=1 Bytes=28)
    14 13 INDEX (UNIQUE SCAN) OF 'av_account_P1' (UNIQUE)
    15 3 TABLE ACCESS (BY INDEX ROWID) OF 'S_ASSET' (Cost=1 Card=1 Bytes=46)
    16 15 INDEX (UNIQUE SCAN) OF 'S_ASSET_P1' (UNIQUE)
    17 2 TABLE ACCESS (BY INDEX ROWID) OF 'S_PROD_INT_X' (Cost=1 Card=1 Bytes=15)
    18 17 INDEX (RANGE SCAN) OF 'S_PROD_INT_X_U1' (UNIQUE) (Cost=1 Card=1)
    19 1 TABLE ACCESS (BY INDEX ROWID) OF 'S_ORG_EXT' (Cost=1 Card=1 Bytes=19)
    20 19 INDEX (UNIQUE SCAN) OF 'S_ORG_EXT_U3' (UNIQUE)
    Below is the No. of records in each table.
    NUM_ROWS     LAST_ANALYZED     TABLE_NAME     BLOCKS
    5,594,027.00     09/08/2006 03:03:02     av_account     92,565.00
    6,659,910.00     09/22/2006 16:14:06     av_event      608,292.00
    15,384,080.00     09/22/2006 15:28:04     S_ASSET     1,244,124.00
    10,249,905.00     04/23/2006 23:51:44     S_ORG_EXT     2,313,814.00
    1,081.00     09/22/2006 15:26:12     S_PROD_INT     129.00
    602.00     09/08/2006 04:39:42     S_PROD_INT_X     10.00

    can you plz try this
    SELECT /*+ LEADING(t2) */ t7.conflict_id, t7.last_upd, t7.created, t7.last_upd_by,
    t7.created_by, t7.modification_num, t7.row_id, t7.last_upd,
    t7.aa_acount_id, t7.aa_last_step, t7.accessory, t7.account_exists,
    t7.account_number, t7.actn_cd, t7.action_counter, t7.activated_by,
    t7.address, t7.address_2, t7.address_validation_status,
    t4.account_name, t7.aggregated_account_id, t7.aggregated_flag,
    t7.asset_id, t7.auto_delivery_type, t7.auto_make, t7.auto_model,
    t7.auto_year, t7.automated_approval, t7.activation_frequency,
    FROM siebel.s_prod_int t1,
    siebel.s_org_ext t2,
    siebel.s_asset t3,
    siebel.av_account t4,
    siebel.s_org_ext t5,
    siebel.s_prod_int_x t6,
    siebel.av_event t7
    WHERE t1.row_id = t6.par_row_id(+)
    AND t7.promotion_code = t1.part_num(+)
    AND t7.asset_id = t3.row_id(+)
    AND t3.owner_accnt_id = t5.par_row_id(+)
    AND t7.id = t2.par_row_id --- S_ORG_EXT_U3
    AND t7.id1 = t4.row_id(+)
    AND (t2.NAME = 'Nichole')
    ORDER BY t7.bot_id, t7.timestp

  • Error Executing Database Query - Help!

    I have a cfquery code that looks like this:
        <CFQUERY DATASOURCE="mydatabase" USERNAME="myuser" PASSWORD="mypassword" NAME="codelist" CACHEDWITHIN="#CreateTimeSpan(0,1,0,0)#">
        SELECT *
        FROM systemcode
        WHERE (LEN(TRIM(systemcode)) = 2 OR LEN(TRIM(systemcode)) = 4)
        <CFSWITCH EXPRESSION="#CAT#">
        <CFCASE VALUE="1">AND (MID(systemcode,1,2) BETWEEN '01' AND '05')</CFCASE>
        <CFCASE VALUE="2">AND (MID(systemcode,1,2) BETWEEN '06' AND '15')</CFCASE>
        <CFCASE VALUE="3">AND (MID(systemcode,1,2) BETWEEN '16' AND '24')</CFCASE>
        <CFCASE VALUE="4">AND (MID(systemcode,1,2) BETWEEN '25' AND '27')</CFCASE>
        <CFCASE VALUE="5">AND (MID(systemcode,1,2) BETWEEN '28' AND '38')</CFCASE>
        <CFCASE VALUE="6">AND (MID(systemcode,1,2) BETWEEN '39' AND '40')</CFCASE>
        <CFCASE VALUE="7">AND (MID(systemcode,1,2) BETWEEN '41' AND '43')</CFCASE>
        <CFCASE VALUE="8">AND (MID(systemcode,1,2) BETWEEN '44' AND '49')</CFCASE>
        <CFCASE VALUE="9">AND (MID(systemcode,1,2) BETWEEN '50' AND '63')</CFCASE>
        <CFCASE VALUE="10">AND (MID(systemcode,1,2) BETWEEN '64' AND '67')</CFCASE>
        <CFCASE VALUE="11">AND (MID(systemcode,1,2) BETWEEN '68' AND '71')</CFCASE>
        <CFCASE VALUE="12">AND (MID(systemcode,1,2) BETWEEN '72' AND '83')</CFCASE>
        <CFCASE VALUE="13">AND (MID(systemcode,1,2) BETWEEN '84' AND '85')</CFCASE>
        <CFCASE VALUE="14">AND (MID(systemcode,1,2) BETWEEN '86' AND '89')</CFCASE>
        <CFCASE VALUE="15">AND (MID(systemcode,1,2) BETWEEN '90' AND '97')</CFCASE>
        <CFCASE VALUE="16">AND (MID(systemcode,1,2) BETWEEN '98' AND '99')</CFCASE>
        <CFDEFAULTCASE><CFLOCATION URL="somewhere.htm"></CFDEFAULTCASE>
        </CFSWITCH>
        ORDER BY systemcode
        </CFQUERY>
    This works perfectly in CF 5.  However, when running in CF 8 I am getting the error message:
    Error Executing Database Query.FUNCTION mydatabase.LEN does not exist The specific sequence of files included or processed is: /home/httpd/vhosts/somedomain.com/httpdocs/reference/systemcode.cfm, line: 24
    (that refers to the above cfquery)
    "mydatabase" is the name of the database and LEN is a function.    It's checking for the length of systemcode to be 2 or 4, if they are then check if the value of #CAT# is 1 and that the first 2 characters is between 01 and 05 then select the row.  I don't know why it works with CF5 but not CF8?  It's driving me nuts.  Any help is appreciated.

    I just don't see why
    all of a sudden it doesn't work with CF8 and MySQL,
    If you changed databases, that is the source of the problem, not upgrading CF.  MySQL will not understand MS Access specific functions and vice versa. Do not expect queries written for one database type to automatically work with another.  While there are sql standards, every database is different. It is quite common for database vendors to have totally different function names, data types and even syntax. You will need to throrougly review your database queries and convert any Access specific syntax, data types, etcetera to the MySQL equivalents.
    Are there MySQL equivalent for these two functions (TRIM and
    LEN)?
    Yes. See the string functions section in the online mySQL docs.
    http://dev.mysql.com/doc/refman/5.0/en/string-functions.html
    I don't konw there was a TRIM and LEN in MS Access
    database.  I guess I was mixing them.
    Yes. It is a little confusing because both CF and MS Access have those functions.  In this specific case you were using the Access functions, not CF.
            http://www.techonthenet.com/access/functions/index_alpha.php
    >> Yes, I did put a
    CFLOCATION inside the cfquery.  Never encounter that
    scenario so I didn't know if it works.
    Well if you are using the code, it should be something you have tested. So you know how it behaves. But CFLOCATION really does not belong inside a database query.
    `

  • Help needed for writing query

    help needed for writing query
    i have the following tables(with data) as mentioned below
    FK*-foregin key (SUBJECTS)
    FK**-foregin key (COMBINATION)
    1)SUBJECTS(table name)     
    SUB_ID(NUMBER) SUB_CODE(VARCHAR2) SUB_NAME (VARCHAR2)
    2           02           Computer Science
    3           03           Physics
    4           04           Chemistry
    5           05           Mathematics
    7           07           Commerce
    8           08           Computer Applications
    9           09           Biology
    2)COMBINATION
    COMB_ID(NUMBER) COMB_NAME(VARCHAR2) SUB_ID1(NUMBER(FK*)) SUB_ID2(NUMBER(FK*)) SUB_ID3(NUMBER(FK*)) SUBJ_ID4(NUMBER(FK*))
    383           S1      9           4           2           3
    384           S2      4           2           5           3
    ---------I actually designed the ABOVE table also like this
    3) a)COMBINATION
    COMB_ID(NUMBER) COMB_NAME(VARCHAR2)
    383           S1
    384           S2
    b)COMBINATION_DET
    COMBDET_ID(NUMBER) COMB_ID(FK**) SUB_ID(FK*)
    1               383          9
    2               383          4
    3               383          2
    4               383          3
    5               384          4
    6               384          2          
    7               384          5
    8               384          3
    Business rule: a combination consists of a maximum of 4 subjects (must contain)
    and the user is less relevant to a COMB_NAME(name of combinations) but user need
    the subjects contained in combinations
    i need the following output
    COMB_ID COMB_NAME SUBJECT1 SUBJECT2      SUBJECT3      SUBJECT4
    383     S1     Biology Chemistry      Computer Science Physics
    384     S2     Chemistry Computer Science Mathematics Physics
    or even this is enough(what i actually needed)
    COMB_ID     subjects
    383           Biology,Chemistry,Computer Science,Physics
    384           Chemistry,Computer Science,Mathematics,Physics
    you can use any of the COMBINATION table(either (2) or (3))
    and i want to know
    1)which design is good in this case
    (i think SUB_ID1,SUB_ID2,SUB_ID3,SUB_ID4 is not a
    good method to link with same table but if 4 subjects only(and must) comes
    detail table is not neccessary )
    now i am achieving the result by program-coding in C# after getting the rows from oracle
    i am using oracle 9i (also ODP.NET)
    i want to know how can i get the result in the stored procedure itsef.
    2)how it could be designed in any other way.
    any help/suggestion is welcome
    thanks for your time --Pradeesh

    Well I forgot the table-alias, here now with:
    SELECT C.COMB_ID
    , C.COMB_NAME
    , (SELECT SUB_NAME
    FROM SUBJECTS
    WHERE SUB_ID = C.SUB_ID1) AS SUBJECT_NAME1
    , (SELECT SUB_NAME
    FROM SUBJECTS
    WHERE SUB_ID = C.SUB_ID2) AS SUBJECT_NAME2
    , (SELECT SUB_NAME
    FROM SUBJECTS
    WHERE SUB_ID = C.SUB_ID3) AS SUBJECT_NAME3
    , (SELECT SUB_NAME
    FROM SUBJECTS
    WHERE SUB_ID = C.SUB_ID4) AS SUBJECT_NAME4
    FROM COMBINATION C;
    As you need exactly 4 subjects, the columns-solution is just fine I would say.

Maybe you are looking for