Simple Pl/SQL query -

Hi,
This might be a simple question, I am new to Pl/SQL ,
I have a table which consists of two columns deal_id and freq.
for each deal_id there might be number of freq. The table something looks similar ltoo this,
deal_id freq
10 1.1
10 1.2
12 1.1
12 1.2
14 1.1
14 1.2
14 1.3
16 1.5
16 1.5
Now if a deal_id selected has freq 1.1 and 1.2 , it should display output has 'MA only'
if a deal_id selected has freq other than 1.1 and 1.2 , it should display 'Not MA'
else if it has like deal_id 14 should display . 'Both Ma and Non MA'
I wrote a query like this,
select
deal_id
, case
When Freq In (1.1 , 1.2) Then 'MA Only'
When Freq Not in (1.1 , 1.2) Then 'Non-MA Only'
Else 'Both Ma and Non-Ma'
End freq_dt
from sample_Table
where ia.deal_id= '14'
O/P i get is
deal_id freq_dt
14 MA only
14 MA only
14 Non MA only
But i should get O/p like
deal_id freq_dt
14 Both MA and Non Ma
Any help will be greatlt appreciated.
Thanks,
Vin

Thanks Guys, for all your valuable suggestions.
These forums are helping me a lot.
Ok, back to the question, after going thru all the posts, i worked out on the query at work for a while and edited it something like this,
Select
case
when count(distinct freq_dt)>1 Then 'Both MA and Non-MA only'
Else <......>(pl refer below)
end status
from
(select
ia.deal_id
, case
when Freq In (851.0125, 851.5125, 852.0125, 852.5125, 853.0215) Then 'MA Only'
When Freq Not in (851.0125, 851.5125, 852.0125, 852.5125, 853.0215) Then 'Non-MA Only'
Else 'Both Ma and Non-Ma'
End freq_dt
from repl_site_freq ia
where ia.deal_id='65'
No worries, I know the query looks like useless, but I am working, I am new to Oracle,
and what i have done is performed a distinct count on the subquery.
Now if count >1 , i mean there is MA and Non-MA so it displays both MA and Non MA. Its working fine.
But now if count = 1, i mean if the whole subquery table has either MA or NOn-MA , then how can i catch that .
I mean if count =1, O/p shud be MA only if all are MA
and NON-MA if all are Non-MA.
Now I want to put this query in the else statement above
select st from
select
ia.deal_id
, case
when Freq In (851.0125, 851.5125, 852.0125, 852.5125, 853.0215) Then 'MA Only'
When Freq Not in (851.0125, 851.5125, 852.0125, 852.5125, 853.0215) Then 'Non-MA Only'
Else 'Both Ma and Non-Ma'
End st
from repl_site_freq ia
where ia.deal_id='32434'
A where rownum < 2
since this subquery just returns count=1, and i want to display the first item in first row of first column which can be either MA or NOn-MA
when i put the above quesry in else, it returns me some error, like groupby missing.
ANy help will be greatly appreciated.
Thanks,
Vin

Similar Messages

  • A simple T-SQL Query

    I am using SQL 2008. I have following table.
    HostName
    Timestamp
    ErrorType
    Server 1
    2014-03-11 00:10:39.387
    N/W Error
    Server 2
    2014-03-11 01:10:40.387
    DB Error
    Server 1
    2014-03-11 00:20:39.387
    N/W Error
    Server 2
    2014-03-11 02:10:40.387
    N/W Error
    Server 2
    2014-03-11 02:00:39.387
    N/W Error
    Server 1
    2014-03-11 03:30:39.387
    N/W Error
    Server 1
    2014-03-11 03:45:39.387
    N/W Error
    Server 1
    2014-03-12 13:45:39.387
    N/W Error
    Server 2
    2014-03-12 14:45:39.387
    DB Error
    I would like to get how many errors occur per hour per server in a particular day. . So basically I will just pass date (such as 2014-03-11) in my query and it will be below report.
    But I am not sure how to get it. Any help would be appreciated
    HostName
    NumberofError
    Time
    Errortype
    Server 1
    2
    12 AM
    N/W Error
    Server 2
    1
    1 AM
    DB Error
    Server 2
    2
    2 AM
    N/W Error
    Server 1
    2
    3 AM
    N/W Error
    Thanks

    Use a table of time slots set to one more decimal second of precision than your data. You can now use temporal math to add it to a DATE to TIME(1) get a full DATETIME2(0). Here is the basic skeleton. 
    CREATE TABLE Timeslots
    (slot_start_time TIME(1) NOT NULL PRIMARY KEY,
     slot_end_time TIME(1) NOT NULL,
     CHECK (start_time < end_time));
    INSERT INTO Timeslots  --15 min intervals
    VALUES ('00:00:00.0', '00:14:59.9'),
    ('00:15:00.0', '00:29:59.9'),
    ('00:30:00.0', '00:44:59.9'),
    ('00:45:00.0', '01:00:59.9'), 
    ('23:45:00.0', '23:59:59.9'); 
    Here is the basic query for rounding down to a time slot. 
    SELECT CAST (@in_timestamp AS DATE), T.start_time
      FROM Timeslots AS T
     WHERE CAST (@in_timestamp AS TIME)
           BETWEEN T.slot_start_time 
               AND T.slot_end_time;
    Also, please stop using AM/PM and learn ANSI/ISO Standards. 
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • Simple Question - SQL Query

    List the branch number and names of shops which do not have any books written by Pratt in stock. Order the list by branch number.
    how can I code this? if that statement was positive, i would say something like "where ..... author_last IN ('Pratt')"
    But in this case, how can I do it? i don't think there's a command like "OUT" in SQL :)

    Hi,
    If you how how to find the shops that DO have such books, then you're off to a good start!
    Make a NOT EXISTS or NOT IN sub-query.
    For example, in the scott.dept table, if you wanted to find all the departments that do not have any salesmen working in them (as found in the scott.emp table):
    SELECT  *
    FROM    scott.dept
    WHERE   deptno  NOT IN ( SELECT  deptno
                             FROM    scott.emp
                             WHERE   job  = 'SALESMAN'
    ;"NOT IN" is sort of like "OUT".

  • Simple dumb sql query

    New user here and I haven't been able to find an answer to this. My table looks like
    Name Code Date Issued Date Returned
    Smith 22 10/05/05 10/10/05
    Smith 3 10/05/05 10/06/05
    Smith 102 10/10/05 10/12/05
    Jones 1 10/10/05 10/11/05
    Code is unique. I want a report for each user that looks like
    Smith 3 10/05/05 10/10/05
    22 10/05/05 10/06/05
    102 10/10/05 10/12/05
    Where the column "Name" does not repeat the value. I have tried various combinations of order by but can't get "name" to stop repeating, and have searched the FAQs and docs but can't find how to do this...I'm sure it's something simple I'm not seeing...thanks in advance

    create table mytable (
        name        varchar2(20)
    ,   code        number
    ,   date_issued date
    ,   date_returned date)
    insert into mytable values ('Smith', 22, to_date('10/05/05','MM/DD/YY'), to_date('10/10/05','MM/DD/YY'))
    insert into mytable values ('Smith', 3, to_date('10/05/05','MM/DD/YY'), to_date('10/06/05','MM/DD/YY'))
    insert into mytable values ('Smith', 102, to_date('10/10/05','MM/DD/YY'), to_date('10/12/05','MM/DD/YY'))
    insert into mytable values ('Jones', 1, to_date('10/10/05','MM/DD/YY'), to_date('10/11/05','MM/DD/YY'))
    select  decode(grp_rn, 1, name, null) name
    ,       code
    ,       date_issued
    ,       date_returned
    from    (   select  m.*
                ,       row_number() over (partition by m.name order by m.name, m.code) grp_rn
                from    mytable m
    NAME     CODE     DATE_ISSUED     DATE_RETURNED
    Jones     1     10/10/2005     10/11/2005
    Smith     3     10/5/2005     10/6/2005
         22     10/5/2005     10/10/2005
         102     10/10/2005     10/12/2005Message was edited by:
    splazm

  • Simple max() sql query

    Dear SQL Experts
    i have data like below
    id rate date
    1 10 03-JAN-2010
    1 20 02-JAN-2010
    1 30 01-JAN-2010
    2 10 01-JAN-2010
    2 20 02-JAN-2010
    2 30 10-JAN-2010
    3 40 01-JAN-2010
    3 50 15-JAN-2010
    3 60 03-JAN-2010
    I want to get the id wise last date's rate. like below
    id rate date
    1 10 03-JAN-2010 (As 3rd Jan is the max date)
    2 30 10-JAN-2010 (As 10th Jan is the max date)
    3 50 15-JAN-2010 (As 15th Jan is the max date)

    You can use the following to avoid the subquery:
    SQL> WITH DATA AS(
      2  select 1 ID1,10 RATE,to_date('03 jan 2010','DD MON YYYY')DATE1 from dual UNION ALL
      3  select 1 ID1,20 RATE,to_date('02 jan 2010','DD MON YYYY')DATE1 from dual UNION ALL
      4  select 1 ID1,30 RATE,to_date('01 jan 2010','DD MON YYYY')DATE1 from dual UNION ALL
      5  select 2 ID1,10 RATE,to_date('01 jan 2010','DD MON YYYY')DATE1 from dual UNION ALL
      6  select 2 ID1,20 RATE,to_date('02 jan 2010','DD MON YYYY')DATE1 from dual UNION ALL
      7  select 2 ID1,30 RATE,to_date('10 jan 2010','DD MON YYYY')DATE1 from dual UNION ALL
      8  select 3 ID1,40 RATE,to_date('01 jan 2010','DD MON YYYY')DATE1 from dual UNION ALL
      9  select 3 ID1,50 RATE,to_date('15 jan 2010','DD MON YYYY')DATE1 from dual UNION ALL
    10  select 3 ID1,60 RATE,to_date('03 jan 2010','DD MON YYYY')DATE1 from dual )
    11  Select id1, max(rate) keep(dense_rank last order by date1) rate, max(date1) date1
    12  from data
    13  group by id1;
           ID1       RATE DATE1
             1         10 03-JAN-10
             2         30 10-JAN-10
             3         50 15-JAN-10Max

  • Pl help with simple pl/sql quey

    Hi ,
    I am getting stuck with this simple pl/sql query , can anyone pl help me with this.
    This is the query i have,
    select ia.deal_id, actual_clear_dt
    from inc_site_freq isf
    join INC_ASSET ia on isf.inc_asset_id = ia.inc_asset_id
    and freq in (866.0125, 866.5125, 867.0125, 867.5125, 868.0125)
    and deal_id=21363
    the above query displays data of about 10 rows which may or may not have combination of null and dates for actua_clear_dt.
    if its a combination of null and dates then all the actual_clear_dt should be null
    if it has only dates should display all dates
    Please help. Thanks.

    Vin wrote:
    Hi ,
    I am getting stuck with this simple pl/sql query , can anyone pl help me with this.
    This is the query i have,
    select ia.deal_id, actual_clear_dt
    from inc_site_freq isf
    join INC_ASSET ia on isf.inc_asset_id = ia.inc_asset_id
    and freq in (866.0125, 866.5125, 867.0125, 867.5125, 868.0125)
    and deal_id=21363
    the above query displays data of about 10 rows which may or may not have combination of null and dates for actua_clear_dt.
    if its a combination of null and dates then all the actual_clear_dt should be null
    if it has only dates should display all dates
    Please help. Thanks.A little indention/formatting would help you see and comprehend it better, and including the { code } tags when posting here would help US see and comprehend it better:
    select
      ia.deal_id,
      actual_clear_dt
    from
      inc_site_freq isf
    join INC_ASSET ia
      on isf.inc_asset_id = ia.inc_asset_id
      and freq in (866.0125,
                   866.5125,
                   867.0125,
                   867.5125,
                   868.0125)
      and deal_id=21363

  • 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:                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • 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 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'

  • 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.

Maybe you are looking for