Need help in SQL Queries using GUI controls or variables

Hello, all
I have a big problem (I have already had with Visual Basic a few mounths ago) with Java while writing my SQL Queries.
I would like to know how I must do to use variable data or GUI control data in my SQL Query to select only some records.
Here, my first Query that works without any problem (no WHERE clause !!!) :
Statement requeteBedes = connectBedes.createStatement();
ResultSet resultatSeries = requeteBedes.executeQuery("SELECT * FROM Series");
initComboBoxSeries(resultatSeries);the method "initComboBoxSeries" fills a JComboBox with all the names of the series in my database.
Here comes my problem.I would like to use the value of the selected "series" in the JComboBox to search in another table of the same Database. I made another statement but it returns a Null ResultSet :
ResultSet resultatSearchAlbumsFromSeries = requeteBedes.executeQuery("SELECT * FROM bandes_dess WHERE  ser_nom = '" + strComboBoxSeriesSelected + "' "); The variable strComboBoxSeriesSelected contains the value of the selected line in the combobox with all the series, filled after the first query that is here above and that works very well.
Could some one help me and tell me how I must use variables or GUI controls values in my SQL Queries or tell me if there is a place where I could find an explanation of that kind of problems (like more "advanced SQL Queries", as the ones currently used in all the Learning Java 2 books)
Thank you all for your help.
Christian.

executeQuery() will never return null. At least that's what the spec says. You are probably catching an exception (probably a syntax error caused by a single quote in strComboBoxSeriesSelected) and ignoring it. Or do you mean the ResultSet contains no rows?
Anyway, to use parameterized queries, take a look at PreparedStatements. Your code should look like this using PreparedStatement:Statement requeteBedes = connectBedes.prepareStatement("SELECT * FROM bandes_dess WHERE  ser_nom = ?");
requeteBedes.setString(1, strComboBoxSeriesSelected);
ResultSet resultatSeries = requeteBedes.executeQuery();Alin.

Similar Messages

  • Need help for SQL Queries Tunning

    hi all,
    we have a procedure for search consumers, which using sql queries like:
    SELECT TRIM (NAME) AS NAME, TRIM (accno) AS accno,
    TRIM (connaddress) AS connaddress,
    TRIM (CATEGORY) AS CATEGORY, TRIM (landmark) AS landmark,
    SUBSTR (accno, 1, 3) AS subdivisionname
    FROM consumermaster
    WHERE LOWER (accno) LIKE
    LOWER ('%' || NVL (caccno, '#noval#') || '%')
    OR LOWER (NAME) LIKE LOWER ('%' || NVL (cname, '#noval#') || '%')
    OR LOWER (connaddress) LIKE
    LOWER ('%' || NVL (cadd, '#noval#') || '%')
    OR phone LIKE '%' || NVL (cphone, '#noval#') || '%'
    OR accno = (SELECT accno
    FROM requestregistration
    WHERE requestid = creqid)
    UNION
    SELECT TRIM (NAME) AS NAME, TRIM (accno) AS accno,
    TRIM (connaddress) AS connaddress, TRIM (CATEGORY)
    AS CATEGORY,
    TRIM (landmark) AS landmark,
    SUBSTR (accno, 1, 3) AS subdivisionname
    FROM scodetails
    WHERE LOWER (accno) LIKE
    LOWER ('%' || NVL (caccno, '#noval#') || '%')
    OR LOWER (NAME) LIKE LOWER ('%' || NVL (cname, '#noval#') || '%')
    OR LOWER (connaddress) LIKE
    LOWER ('%' || NVL (cadd, '#noval#') || '%')
    OR phone LIKE '%' || NVL (cphone, '#noval#') || '%'
    OR accno = (SELECT accno
    FROM requestregistration
    WHERE requestid = creqid);
    it's ok for small tables but now data increase .......
    searching method is very slow
    now i want to tune this query for better performance
    please sugg me best method
    Thanks in advance
    Regards
    vij..

    The link given by Asif should get you on the right track for tuning this query.
    I just formatted your SQL:
    SELECT Trim(NAME)        AS NAME,
           Trim(accno)       AS accno,
           Trim(connaddress) AS connaddress,
           Trim(category)    AS category,
           Trim(landmark)    AS landmark,
           Substr(accno,1,3) AS subdivisionname
    FROM   consumermaster
    WHERE  Lower(accno) LIKE Lower('%'
                                   ||Nvl(caccno,'#noval#')
                                   ||'%')
            OR Lower(NAME) LIKE Lower('%'
                                      ||Nvl(cname,'#noval#')
                                      ||'%')
            OR Lower(connaddress) LIKE Lower('%'
                                             ||Nvl(cadd,'#noval#')
                                             ||'%')
            OR phone LIKE '%'
                          ||Nvl(cphone,'#noval#')
                          ||'%'
            OR accno = (SELECT accno
                        FROM   requestregistration
                        WHERE  requestid = creqid)
    UNION
    SELECT Trim(NAME)        AS NAME,
           Trim(accno)       AS accno,
           Trim(connaddress) AS connaddress,
           Trim(category)    AS category,
           Trim(landmark)    AS landmark,
           Substr(accno,1,3) AS subdivisionname
    FROM   scodetails
    WHERE  Lower(accno) LIKE Lower('%'
                                   ||Nvl(caccno,'#noval#')
                                   ||'%')
            OR Lower(NAME) LIKE Lower('%'
                                      ||Nvl(cname,'#noval#')
                                      ||'%')
            OR Lower(connaddress) LIKE Lower('%'
                                             ||Nvl(cadd,'#noval#')
                                             ||'%')
            OR phone LIKE '%'
                          ||Nvl(cphone,'#noval#')
                          ||'%'
            OR accno = (SELECT accno
                        FROM   requestregistration
                        WHERE  requestid = creqid); You are using some function on almost each and every column in the where clause. Try getting rid of them as they are hindering the use of indexes, if any, on any of the columns.
    Also the guidelines in the link provided are the best starting point.

  • NEED HELP IN SQL+ CODING USING POINTERS

    GOOD MORNING BOARD,
    I HAVE A CODING ISSUE DEALING WITH POINTERS AND BUILDING TABLES USING THEM CAN SOMEONE PLEASE HELP??
    I CAN SEND THE CODE TO U VIA ATTACHMENT
    THANK YOU IN ADVANCE
    A...

    GOOD MORNING BOARD,
    I HAVE A CODING ISSUE DEALING WITH POINTERS AND BUILDING TABLES USING THEM CAN SOMEONE PLEASE HELP??
    I CAN SEND THE CODE TO U VIA ATTACHMENT
    THANK YOU IN ADVANCE
    A...

  • Retrieving SQL queries used in BO reports using BO Java SDKs

    Hi,
    Is it possible to retrieve SQL queries generated by Canned Reports? I have 200+ reports saved in my local system and i need to retrieve SQL queries from them, this is required for documentation purpose. Please let me know if it is possible thru BO java SDKs.

    This is the code I am using to retrieve the SQL values.
    IEnterpriseSession boEnterpriseSession = null;
                  boEnterpriseSession = CrystalEnterprise.getSessionMgr().logon( boUser, boPassword, boCmsName, boAuthType);
                   // Get the Report Application Factory service from Crystal Enterprise
                   IReportAppFactory rptAppFactory = (IReportAppFactory)boEnterpriseSession.getService("", "RASReportService");
                   // Get the InfoStore service from Crystal Enterprise
                   IInfoStore boInfoStore = (IInfoStore)boEnterpriseSession.getService("", "InfoStore");
                   // Retrieve the report by name from Crystal Enterprise
                   IInfoObjects boInfoObjects = boInfoStore.query("Select SI_ID From CI_INFOOBJECTS Where SI_NAME = '" + reportName + "'");
                   // Open the report into a Report Document object
                   ReportClientDocument rcd = rptAppFactory.openDocument((IInfoObject)boInfoObjects.get(0), 0, Locale.ENGLISH);
                   System.out.println("SQL query \n \n");
                   System.out.println(rcd.getRowsetController().getSQLStatement(null, ""));
    I am a newbie and I dont understand where the error lies.. Please help me out.
    regards,
    nitin
    When run the code gives  the following errors
    com.crystaldecisions.sdk.occa.managedreports.ras.internal.ManagedRASException: Cannot open report document. --- 0x80004005
    Unspecified error
    cause:com.crystaldecisions.sdk.occa.report.lib.ReportSDKServerException: 0x80004005
    Unspecified error---- Error code:-2147467259 Error code name:failed
    detail: 0x80004005
    Unspecified error
         at com.crystaldecisions.sdk.occa.managedreports.ras.internal.RASReportAppFactory.a(Unknown Source)
         at com.crystaldecisions.sdk.occa.managedreports.ras.internal.RASReportAppFactory.a(Unknown Source)
         at com.crystaldecisions.sdk.occa.managedreports.ras.internal.RASReportAppFactory.openDocument(Unknown Source)
         at com.crystaldecisions.sdk.occa.managedreports.ras.internal.RASReportAppFactory.openDocument(Unknown Source)
         at com.hcl.BO.retrieveSql.RetrieveSQL.main(RetrieveSQL.java:44)
    Caused by: com.crystaldecisions.sdk.occa.report.lib.ReportSDKServerException: 0x80004005
    Unspecified error---- Error code:-2147467259 Error code name:failed
         at com.crystaldecisions.sdk.occa.report.lib.ReportSDKServerException.throwReportSDKServerException(Unknown Source)
         at com.crystaldecisions.proxy.remoteagent.s.a(Unknown Source)
         at com.crystaldecisions.sdk.occa.report.application.ReportClientDocument.if(Unknown Source)
         at com.crystaldecisions.sdk.occa.report.application.ReportClientDocument.if(Unknown Source)
         at com.crystaldecisions.sdk.occa.report.application.ReportClientDocument.a(Unknown Source)
         at com.crystaldecisions.sdk.occa.report.application.ClientDocument.open(Unknown Source)
         ... 4 more
    I am a newbie and

  • I need help I tried to use cloud backup on my iPhone 5.0.1 and after all my camera roll pictures are blurry and videos canot be played messege says URL not on this server ! Please help!! iPhone 4S, iOS 5.0.1

    I need help I tried to use cloud backup on my iPhone 5.0.1 and after all my camera roll pictures are blurry and videos canot be played messege says URL not on this server ! Please help!!
    iPhone 4S, iOS 5.0.1

    Try updating to iOS 6.1.3.

  • Need help writing host program using LabView.

    Need help writing host program using LabView.
    Hello,
    I'm designing a HID device, and I want to write a host program using National Instrument's LabView. NI doesn't have any software support for USB, so I'm trying to write a few C dll files and link them to Call Library Functions. NI has some documentation on how to do this, but it's not exactly easy reading.
    I've written a few C console programs (running Win 2K) using the PC host software example for a HID device from John Hyde's book "USB by design", and they run ok. From Hyde's example program, I've written a few functions that use a few API functions each. This makes the main program more streamlined. The functions are; GetHIDPath, OpenHID, GetHIDInfo, Writ
    eHID, ReadHIC, and CloseHID. As I mentioned, my main program runs well with these functions.
    My strategy is to make dll files from these functions and load them into LabView Call Library Functions. However, I'm having a number of subtle problems in trying to do this. The big problem I'm having now are build errors when I try to build to a dll.
    I'm writing this post for a few reasons. First, I'm wondering if there are any LabView programmers who have already written USB HID host programs, and if they could give me some advice. Or, I would be grateful if a LabView or Visual C programmer could help me work out the programming problems that I'm having with my current program. If I get this LabView program working I would be happy to share it. I'm also wondering if there might already be any USB IHD LabView that I could download.
    Any help would be appreciated.
    Regards, George
    George Dorian
    Sutter Instruments
    51 Digital DR.
    Novato, CA 94949
    USA
    [email protected]
    m
    (415) 883-0128
    FAX (415) 883-0572

    George may not answer you.  He hasn't been online here for almost eight years.
    Jim
    You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice

  • Need help with SQL Query with Inline View + Group by

    Hello Gurus,
    I would really appreciate your time and effort regarding this query. I have the following data set.
    Reference_No---Check_Number---Check_Date--------Description-------------------------------Invoice_Number----------Invoice_Type---Paid_Amount-----Vendor_Number
    1234567----------11223-------------- 7/5/2008----------paid for cleaning----------------------44345563------------------I-----------------*20.00*-------------19
    1234567----------11223--------------7/5/2008-----------Adjustment for bad quality---------44345563------------------A-----------------10.00------------19
    7654321----------11223--------------7/5/2008-----------Adjustment from last billing cycle-----23543556-------------------A--------------------50.00--------------19
    4653456----------11223--------------7/5/2008-----------paid for cleaning------------------------35654765--------------------I---------------------30.00-------------19
    Please Ignore '----', added it for clarity
    I am trying to write a query to aggregate paid_amount based on Reference_No, Check_Number, Payment_Date, Invoice_Number, Invoice_Type, Vendor_Number and display description with Invoice_type 'I' when there are multiple records with the same Reference_No, Check_Number, Payment_Date, Invoice_Number, Invoice_Type, Vendor_Number. When there are no multiple records I want to display the respective Description.
    The query should return the following data set
    Reference_No---Check_Number---Check_Date--------Description-------------------------------Invoice_Number----------Invoice_Type---Paid_Amount-----Vendor_Number
    1234567----------11223-------------- 7/5/2008----------paid for cleaning----------------------44345563------------------I-----------------*10.00*------------19
    7654321----------11223--------------7/5/2008-----------Adjustment from last billing cycle-----23543556-------------------A--------------------50.00--------------19
    4653456----------11223--------------7/5/2008-----------paid for cleaning------------------------35654765-------------------I---------------------30.00--------------19
    The following is my query. I am kind of lost.
    select B.Description, A.sequence_id,A.check_date, A.check_number, A.invoice_number, A.amount, A.vendor_number
    from (
    select sequence_id,check_date, check_number, invoice_number, sum(paid_amount) amount, vendor_number
    from INVOICE
    group by sequence_id,check_date, check_number, invoice_number, vendor_number
    ) A, INVOICE B
    where A.sequence_id = B.sequence_id
    Thanks,
    Nick

    It looks like it is a duplicate thread - correct me if i'm wrong in this case ->
    Need help with SQL Query with Inline View + Group by
    Regards.
    Satyaki De.

  • I need help from chile and use a language translator to write and not turn my iphone4

    I need help from chile and use a language translator to write and not turn my iphone4

    http://support.apple.com/kb/TS3281       
    Not turn on

  • Need a help: how to recover using backup control file?

    Please a help:
    First computer
    1. I create a database
    2. put it in archive mode,
    3. shutdown and made a cold backup
    4. Created backup control file (alter database backup control file to trace)
    5. I started up and created some archived log files.
    Second Computer
    1. I copied all files created in the step 3 above except the control file
    2. I create all the same map directory on the 2nd computer as in the 1st computer
    3. I recreate the control file from the script got in the step 4 above
    4. I Copy archived log files generated at the step 5 in the local directory in the second computer
    5. I set the logsource and set the autorecovery to on
    6. I recover the database: RECOVER DATABASE USING BACKUP CONTROL FILE UNTIL CANCEL
    Error got:
    the archived log file applied do not go beyond the first one?,How could I do to applied all archived log files copied from the first computer to the second computer to have the same data?
    Thank you very much

    archived log sequeces in the first computerSQL> select sequence#,first_change#,next_change# from v$log_history;
    SEQUENCE# FIRST_CHANGE# NEXT_CHANGE#
    1 553723 555484
    2 555484 557345
    Actions I did in the second Computer(after copied the former two archived log files from the 1st computer)
    SQL> CREATE CONTROLFILE REUSE DATABASE "ORCL" RESETLOGS ARCHIVELOG
    2 MAXLOGFILES 16
    3 MAXLOGMEMBERS 3
    4 MAXDATAFILES 100
    5 MAXINSTANCES 8
    6 MAXLOGHISTORY 292
    7 LOGFILE
    8 GROUP 1 'C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\REDO01.LOG' SIZE 50M,
    9 GROUP 2 'C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\REDO02.LOG' SIZE 50M,
    10 GROUP 3 'C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\REDO03.LOG' SIZE 50M
    11 -- STANDBY LOGFILE
    12 DATAFILE
    13 'C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\SYSTEM01.DBF',
    14 'C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\UNDOTBS01.DBF',
    15 'C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\SYSAUX01.DBF',
    16 'C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\USERS01.DBF'
    17 CHARACTER SET WE8ISO8859P1
    18 ;
    Control file created.
    SQL> archive log list;
    Database log mode Archive Mode
    Automatic archival Disabled
    Archive destination USE_DB_RECOVERY_FILE_DEST
    Oldest online log sequence 0
    Next log sequence to archive 0
    Current log sequence 0
    SQL> alter database archivelog;
    Database altered.
    SQL> set logsource C:\local_destination1_orcl
    SQL> set autorecovery on;
    SQL> recover database using backup controlfile until cancel;
    ORA-00279: change 555611 generated at 01/18/2007 14:14:14 needed for thread 1
    ORA-00289: suggestion :
    C:\LOCAL_DESTINATION1_ORCL\ARCH.1_1_612194518_43F17CF5.ARC
    ORA-00280: change 555611 for thread 1 is in sequence #1
    ORA-00328: archived log ends at change 555483, need later change 555611
    ORA-00334: archived log:
    'C:\LOCAL_DESTINATION1_ORCL\ARCH.1_1_612194518_43F17CF5.ARC'
    Idon't know where the change 555611 is coming from?

  • Need help on how a user can control a video clip using their mouse

    I need help. I've got a video clip of a rotating 3D
    object(left to right) and i would like the user to be able to
    control the rotation of the object using their mouse. I've looked
    everywhere and i'm at a lost. Can anyone help me
    Here is a link to what i'm trying to achieve:
    http://www.sun.com/servers/blades/6000/gallery/index.xml?p=1&s=2
    I know they use Java but i'm sure this can be done in Flash.
    Thanks
    Ray

    Just use the plain linear fit!
    (If you are discussing something you found in the forum, you should always include a link so we can see what you area talking about. What you probably found was a workaround that forces an intercept of zero for a special scenario. If you want to use general linear fit anyway, your matrix simply also needs a constant term)
    If you still have problems, show us your code and some data.
    LabVIEW Champion . Do more with less code and in less time .

  • Need help  transfer sql o/p as email using Shell scirpt

    Hi all
    I tring to Email the sql report using the shell script
    I am using this command in the shell script
    Then how to initialize the org_id ?
    I written fnd_client_info.set_org_contex(fnd_profile.value('org_id'); in the sql script. is this the write way to write
    Can any one help on this..
    Edited by: Sravprem on Sep 20, 2012 1:46 AM

    Hi Helios
    Our Erp vesion was 11i & i tried like below in sql script (to initialize the org_id). program was error outed .. Can you tell how to use view in sql script
    set lines 32767
    set feedback off
    set emb on pages 0 newp 0
    set trimspool on
    set tab off
    set trimout on
    set echo off
    set underline off
    set verify off
    set show off
    set head off
    set colsep,
    COLUMN ERR_REC_CNT format a500 HEADING 'ERROR_RECORD_COUNT'
    COLUMN PRCS_STTS_FLG format a10 HEADING 'PROCESS_FLAG'
    COLUMN CREATION_DATE format a35 HEADING 'CREATION_DATE'
    BEGIN
    FND_CLIENT_INFO.SET_ORG_CONTEXT(FND_PROFILE.VALUE('ORG_ID'));
    END;
    SELECT 'ERROR_RECORD,PROCESS_STATUS_FLAG,CREATION_DATE'
    FROM DUAL
    UNION ALL
    SELECT order_number ||',' ||
    customer_number ||',' ||
    line_number
    FROM oe_order_lines_v;
    EXIT;
    /

  • Need help on SQL Statement for UDF

    Hi,
    as I am not so familiar with SQL statements on currently selected values, I urgently need help.
    The scenario looks as follows:
    I have defined two UDFs named Subgroup1 and Subgroup2 which represent the subgroups dependent on my article groups. So for example: When the user selects article group "pianos", he only sees the specific subgroups like "new pianos" and "used pianos" in field "Subgroup1". After he has selected one of these specific values, he sees only the specific sub-subgroups in field "Subgroup2", like "used grand pianos".
    I have defined UDTs for both UDFs. The UDT for field "Subgroup1" has a UDF called "ArticleGroup" which represents the relation to the article group codes. The UDT for field "Subgroup2" has a UDF called "Subgroup1" which represents the relation to the subgroups one level higher.
    The SQL statement for the formatted search in field "Subgroup1" looks as follows:
    SELECT T0.[Name] FROM [dbo].[@B_SUBGROUP1]  T0 WHERE T0.[U_ArticleGroup]  = (SELECT $[OITM.ItmsGrpCod])
    It works fine.
    However, I cannot find the right statement for the formatted search in field "Subgroup2".
    Unfortunately this does NOT WORK:
    SELECT T0.[Name] FROM [dbo].[@B_SUBGROUP2]  T0 WHERE T0.[U_Subgroup1]  = (SELECT $[OITM.U_Subgroup1])
    I tried a lot of others that didn't work either.
    Then I tried the following one:
    SELECT T0.[Name] FROM [dbo].[@B_SUBGROUP2]  T0 WHERE T0.[U_Subgroup1] = (SELECT T1.[Code] FROM [dbo].[@B_SUBGROUP1] T1 WHERE T1.[U_ArticleGroup] = (SELECT $[OITM.ItmsGrpCod]))
    Unfortunately that only works as long as there is only one specific subgroup1 for the selected article group.
    I would be sooooo happy if there is anyone who can tell me the correct statement for my second UDF!
    Thanks so much in advance!!!!
    Edited by: Corinna Hochheim on Jan 18, 2010 10:16 PM
    Please ignore the "http://" in the above statements - it is certainly not part of my SQL.
    Please also ignore the strikes.

    Hello Dear,
    Use the below queries to get the values:
    Item Sub Group on the basis of Item Group
    SELECT T0.[Name] FROM [dbo].[@SUBGROUP]  T0 WHERE T0.[U_GroupCod] =$[OITM.ItmsGrpCod]
    Item Sub Group 1 on the basis of item sub group
    SELECT T0.[Name] FROM [dbo].[@SUBGROUP1]  T0 WHERE T0.[U_SubGrpCod]=(SELECT T0.[Code] FROM [dbo].[@SUBGROUP]  T0 WHERE T0.[Name] =$[OITM.U_ItmsSubgrp])
    Sub group 2 on the basis of sub group 1
    SELECT T0.[Name] FROM [dbo].[@SUBGROUP2]  T0 WHERE T0.[U_SubGrpCod1]=(SELECT T0.[Code] FROM [dbo].[@SUBGROUP1]  T0 WHERE T0.[Name] =$[OITM.U_ItmsSubgrp1])
    this will help you.
    regards,
    Neetu

  • Need help in SQL (DENSE_RANK) function

    Hello All,
    I need the help in SQL.
    We have a table called status and the column are
    status_id number
    account_id number
    status_cd varchar2(10)
    created_id varchar2(10)
    created_by date
    and data is as follows
    insert into status values (1,101,'ENTER','ABC',to_date('21-JAN-2007 11:15:14','DD-MON-YYYY HH:MI:SS'));
    insert into status values (2,101,'REVIEW','DEF',to_date('21-JAN-2007 11:30:25','DD-MON-YYYY HH:MI:SS'));
    insert into status values (3,101,'APPROVE','GHI',to_date('21-JAN-2007 11:30:25','DD-MON-YYYY HH:MI:SS'));
    insert into status values (4,102,'ENTER','ABC',to_date('21-JAN-2007 11:18:14','DD-MON-YYYY HH:MI:SS'));
    insert into status values (5,102,'REVIEW','DEF',to_date('21-JAN-2007 11:33:25','DD-MON-YYYY HH:MI:SS'));
    insert into status values (6,102,'CANCEL','GHI',to_date('21-JAN-2007 11:33:25','DD-MON-YYYY HH:MI:SS'));
    insert into status values (7,103,'ENTER','ABC',to_date('21-JAN-2007 11:21:14','DD-MON-YYYY HH:MI:SS'));We have different status as follows
    1. ENTER
    2. REVIEW
    3. APPROVE
    4. CANCEL
    5. REJECT
    My requirement ..
    I need the max of created_id column for the status in ('APPROVE','CANCEL') and if there is no status in ('APPROVE','REVIEW') than it should be NULL.
    I wrote an SQL as
    select account_id,max(created_id) keep (dense_rank first order by decode(status_cd,'APPROVE',created_dt,'REVIEW',created_dt,NULL) DESC NULLS LAST,
          decode(status_cd,'APPROVE',status_id,'REVIEW',status_id,NULL) DESC NULLS LAST) last_app_rev_user
    from status
    group by account_id and gives me the output like
    ACCOUNT_ID LAST_APP_R
           101 GHI
           102 DEF
           103 ABCBut I want the Output like
    ACCOUNT_ID LAST_APP_R
           101 GHI
           102 DEF
           103 NULLAs the account 103 has no status called 'REVIEW' and 'APPROVE'
    My DB Version in 10.2.0.3.0.
    Hope I explain it properly. And if you have any other option without dense_rank still i will be happy.
    Thanks in advance for your help.
    AB
    null
    Message was edited by:
    AB

    instead of max(created_id) keep... use
    smth like max(case when status_cd in ('APPROVE','REVIEW') then created_id end) keep...

  • Need Help On SQL Statement

    I am using Sybase as my back end database. I need help on my SQL statement regarding datetime. The datetime is store as a 9 digit integer in the database (...I believe it is a Decimal(30,6) format, let me know if I am wrong).
    If I do this, "select * from mytable;" It works out fine (except I don't know what the date means e.g. 998919534)
    If I do this, "select * from mytable where datetime_col < '9/5/2002' ; I got an error. I even tried '9/5/02 11:00 000 am' but it didn't help.
    How do I specify a date or datetime in my query?
    Thanks in advance.

    I execute the sql statement
    select * from mytable where datetim_col < convert(datetime, '3/4/2002', 101) ;
    I got mix result. I got an error message "cannot convert 10375584 to a date.
    Yet, he statistics window of the I-sql says
    "estimated 493 rows in query (I/O estimate 87)
    PLan> mytable (seq)"
    It looks like I my the SQL statement is correct and then the system can't display it in the Data window.
    Any thought ?

  • Need help converting SQL "OVER (PARTITION BY   )" to JPQL equivalent - JPA

    Having trouble converting this query:
    select
    sdi,
    val,
    vldtn,
    TO_CHAR(sdt, 'yyyy-mm-dd hh:mi:ss AM')
    from
    select
    sdi,
    val,
    vldtn,
    sdt,
    max(sdt) over (partition by sdi) as MaxDate1
    from
    r_ins
    ) x
    where x.sdt = x.MaxDate1
    and sdi in (1234,2345,3456,4567,5678,6789,7890);
    to JPQL equivalent using JPA
    Able to convert simple queries but I do not know how to handle the "over (partition by sdi)" portion of the query.
    Can anyone help
    TIA
    Jer

    Paul Horth wrote:
    Why have the power (and cost) of Oracle and then not use those powerful features because you are restricting yourself to a vanilla set of SQL because you are using some generic framework.You know how it is :
    1 - Application developers create code & queries but only test them on tiny database with low volume and no concurrency at all.
    2 - Application goes Live, Database grows (as expected) but stupid optimizer is not as fast as on test environment (that was mostly empty)
    3 - Queries are now 200 times slower.
    4 - Expensive DB expert comes and gathers statistics, creates indexes, rewrites queries, uses hint/outline/SQLprofile.
    Conclusion : Database is evil and prevent application from working efficiently, the proof of all that being : nothing had to be done on application's side to make things work correctly. Database is declared guilty.
    Which could translate to :
    1 - Team buy a formula one with 800HP that can reach 200mph in less than 10 seconds.
    2 - Give it a pilot that doesn't even want to understand what-the-heck is a gearbox/transmission. Pilot only drives in 1st gear.
    3 - The formula one is now doing 0.003 miles per gallon, doing the hell of a noise, and is limited to 80mph +(any $10000 family wagon is faster in average)+
    4 - Expensive expert comes and check everything in the formula one. Finally understand the problem and modify the gearbox to a sloppy automatic transmission
    Conclusion : Formula 1 is evil and prevent pilot from being fast. The proof of that being : nothing had to be changed on pilot's side to make things work correctly. Formula 1 is declared guilty.
    You cannot win race without understanding how the car/engine/transmission/physics/race rules work.
    Too much levels of abstraction is bad. Treating the database as a black box is the most seen "Bad Idea" these days (to my point of view).
    Warning: I am biased towards Oracle :-)And so am I.
    (^_^)

Maybe you are looking for