SELECT statement not returning NULL records

I have the following SELECT statement:
SELECT *
FROM RPT_DS1_CNT_CAT
WHERE DUPS_SAME <> 'N/A';
I also tried:
SELECT *
FROM RPT_DS1_CNT_CAT
WHERE DUPS_SAME != 'N/A';
Same results - There ARE Null DUPS_SAME values
which are not being selected. I get NO results.
When I execute this, I do get NULL values.
SELECT *
FROM RPT_DS1_CNT_CAT
WHERE DUPS_SAME IS NULL;
How can I ensure that I get all non - 'N/A' records
if it won't pick up the nulls? Is there a function
I can use or a different wording? I do want to use
!= or <> because there may be other values besides
'N/A' such as 'YES' or 'NO' and they may be null or
filled with spaces.

The expression
NVL(DUPS_SAME,'') is meaningless. You're saying "If DUPS_SAME is NULL, return the empty string, which is NULL, otherwise return DUPS_SAME." If you're going to use NVL, the string that gets returned if the column is NULL should be non-NULL, i.e.
NVL(DUPS_SAME,'DUPS_SAME was NULL') Your query should, as others have pointed out, either be
SELECT *
  FROM rpt_ds1_cnt_cat
WHERE dups_same <> 'N/A' OR dups_same IS NULLor
SELECT *
  FROM rpt_ds1_cnt_cat
WHERE NVL(dups_same, 'DUPS_SAME is NULL') <> 'N/A' Either of these return the same results as your query but they're going to be far clearer for whoever needs to maintain the code. There may be performance differences as well if DUPS_SAME is indexed depending on the data distribution...
Justin

Similar Messages

  • Select statement not returning correct data

    I'm working on an application and I'm having a weird problem. The application connects to an Oracle database, pulls out some data, and does something with it. In the process of testing I've already read and dealt with some rows. On those rows the UPDATE_FLAG field was changed to a N so they wouldn't be selected again.
    I do want to select those rows again, so with SQLPlus I changed the UPDATE_FLAG back to Y. Now here's the strange part. The same select statement run from SQLPlus is returning thoe row I modified, but my application does not.
    Here's the select statement:
    SELECT * FROM MY_TABLE WHERE UPDATE_FLAG = 'Y' and USER_ID like 'B%';
    When I run this I get a row back called Brian.
    In my application I do this:
    try
                   Class.forName("oracle.jdbc.driver.OracleDriver");               
                   Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@server:port:sid", "username", "password");
                   Statement st = conn.createStatement();
                   ResultSet rec = st.executeQuery("SELECT * FROM MY_TABLE WHERE UPDATE_FLAG = 'Y' and USER_ID like 'B%'");
                   System.out.println("SELECT * FROM MY_TABLE WHERE UPDATE_FLAG = 'Y' and USER_ID like 'B%'");
                   while(rec.next())
                        System.out.println(rec.getString("USER_ID"));
                   st.close();
              } catch (Exception e)
                   System.out.println("Error -- " + e.toString());
                   e.printStackTrace();
                }When this runs it doesn't return Brian and there are no exceptions caught. It's like it does not find it.
    Assuming I explained this well enough, anyone have any ideas what the problem could be?
    Thanks,
    James

    I do want to select those rows again, so with SQLPlus I changed the UPDATE_FLAG back to Y. Last time I ran SQLPlus I explicitly had to do a commit after modifications, because it was creating a transaction around the sqlplus session. Of course running a query in that session would work on the modified data rather than the actual data.

  • Need help using Select statement  to  retrieve one record

    Hi guys, my first post so be gentle please. The basis of this fucntion is to search my dtabase using the select statement to find the record the user wants, by retrieving the name of theitem from the text box. details are then displayed on a joption message box.
    Everytime I run this program it throws an exception 'Exception: null'. Can anyone see where I am going wrong, I have only bn learning java for thepast 6 months so perhaps I am doing something wrong.
    Or perhaps there is another way for me to close the st, con, rs?
    Your help appreciated
    public void searchproducts(){
    Connection con = null;
    Statement st = null;
    ResultSet rs = null;
    try{
    //creating and loading a database connection
    String dbUrl = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=db2.mdb;"; // String dbUrl = "jdbc:odbc:people";
    String user = "";
    String password = "";
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection c = DriverManager.getConnection(
    dbUrl, user, password);
    int count;
    st = con.createStatement();
    rs = st.executeQuery("SELECT ItemName, Country, Yearmade, ValuePrice, Forsale FROM Collectman WHERE ItemName="+" '"+txtsearchproduct.getText()+"'" );
    while(rs.next()) {
    String ItemName = rs.getString(1);
    String Country = rs.getString(2);
    String Yearmade = rs.getString(3);
    String ValuePrice = rs.getString(4);
    String Forsale = rs.getString(5);
    JOptionPane.showMessageDialog(null, "product details are: " + ItemName + " " + Country + " " + Yearmade + " " + ValuePrice + " " + Forsale);
    //It keeps on throwing this excpetion with null
    catch (Exception e) {
    System.err.println("Exception: " + e.getMessage());
    } finally {
    try {
    if(rs != null)
    rs.close();
    if(st != null)
    st.close();
    if(con != null)
    con.close();
    } catch (SQLException e) {
    }

    And while we're waiting on that, I'll just say it's nice to see you almost got the general layout of a db call correct...that's a rare thing around here. The finally should have a try/catch round each of the close statements and not around all three in one go. If the resultset throws an exception in your version then you would fail to close either the statement or the connection.
    The second thing is, look up PreparedStatements. They're a better choice for handling SQL requiring variables than using a bog standard Statement.

  • Case Statement Not returning resutlset Varbinary

    Declare @val varbinary
    set @val = cast('123456789' as varbinary) 
    select @val as value -- Varbinary Value Result
    Declare @check bit
    set @check= 1
    --THis Case Statement Not returning Result set in Varbinary  . 
    select case @check when 1 then @val else 1 end as value

    See the below part from MSDN documentation reg return type
    Returns the highest precedence
    type from the set of types in result_expressions and
    the optional else_result_expression. 
    http://msdn.microsoft.com/en-IN/library/ms181765.aspx
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • I want a select statement to return two values, sum of one column and customer number

    I have two columns one called invoice_number and the other invoice_amount. I want a select statement to return two columns.... invoice_number and then the sum of the invoice_amount(s) for each unique invoice number.
    SELECT sum(invoice_amount) AS Totalinvoice_amount FROM InvoiceTB where invoice_number = 'INV102'
    This is where I've started, which returns:
    Totalinvoice_amount
    500.00
    Any help is appreciated.
    Please mark my post as helpful or the answer or better yet.... both! :) Thanks!

    Please post DDL, so that people do not have to guess what the keys, constraints, Declarative Referential Integrity, data types, etc. in your schema are. Learn how to follow ISO-11179 data element naming conventions and formatting rules. Temporal data should
    use ISO-8601 formats. Code should be in Standard SQL as much as possible and not local dialect. 
    This is minimal polite behavior on SQL forums. 
    --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

  • Select statement not working

    hi to all,
    I am trying to write use inner joining . here is code
    DATA:tabname LIKE dd02L-tabname,
         table_disc LIKE dd02t-ddtext.
      SELECT  dd02ltabname dd02tddtext INTO (tabname,table_disc)
        FROM dd02l INNER JOIN dd02t on dd02ltabname = dd02ttabname
              WHERE dd02tddlanguage = 'E' AND dd02ltabclass = 'TRANSP'
                                AND dd02L~tabname = 'ZANKI*'.
        endselect.
          write : tabname.
    I also checked in tables dd02t and dd02l for the table zanki* and data available in both table . but here select statement not working .do u have any idea about this. thank you

    Hi,
    I executed the ur inner join conditin by commenting 'z*' it's working fine.
    I think  where condition is not getting satisfied so u r not getting any data.
    Please conform in where condition you need * 'AND'* or OR
    I change decalration as below.
    DATA:tabname    type TABNAME,
          table_disc type AS4TEXT.
    SELECT dd02l~tabname
           dd02t~ddtext  INTO (tabname, table_disc)
    FROM dd02l  INNER JOIN dd02t on dd02l~tabname = dd02t~tabname
    WHERE dd02t~ddlanguage = 'E' AND
          dd02l~tabclass = 'TRANSP'AND
        dd02L~tabname = 'ZANKI*'.
    endselect.
    write : tabname.
    Regards,
    Pravin

  • Howto create 'select statement' that returns first row? (simple table)

    quick question that drives me crazy:
    Say I have the following table:
    ID....car_model....point_A....total
    1........333.............NY..........54
    2........333.............NJ..........42
    3........333.............NH...........63
    4........555.............NJ...........34
    5........555.............PA...........55
    I would like to create a select statement that return car_model which the starting point is NJ - in this example it's only 555.
    thanks for any tips

    fair enough.
    the problem is this: given the table below, I need to create a report that reflects car rentals from specific location. you can rent a car from different locations; a car has a starting point (like a flight itinerary) so consider this:
    Mark rent a car with the following itinerary:
    NY--> NJ
    NJ--> PA
    PA-->FL
    FL-->LA
    the end user would like to see all car that were rented between X and Y and start point was NJ, so in the example above, the starting point is NY so it doesn't match the end users' criteria.
    The table is organized in the following manner: ID....car_model....point_A....total
    * I don't know whey the someone choose point_A as a column description as it just suppose to be 'location'
    so, back to my first example:
    ID....car_model....point_A....total
    1........333.............NY..........54
    2........333.............NJ..........42
    3........333.............NH...........63
    4........555.............NJ...........34
    5........555.............PA...........55
    if I do this:
    Select car_model from myTable where point_A='NJ'
    the return result will be 333 and 555 but that is in correct because 333 starting point is NY.
    I hope I provided enough information, thanks

  • Subquery not returning NULL rows

    Hi,
    I have been working with SQL since very long, but sorry, I have not come across following problem.
    In the FROM clause, I use one sub query and a table. If I run sub query alone, it lists records even if rows with RATE=NULL.
    But when I join sub query with other table, it is not fetching any records for RATE=NULL.
    SELECT *
    FROM
    (SELECT key, perceivedseverity, eventtime, nvl(rate,'NA') rate FROM tr_alarm_history a
    WHERE eventtime = (SELECT MAX(eventtime) FROM tr_alarm_history WHERE key = a.key)) a,
    tr_lot_list b
    WHERE a.key = b.localtargetname
    and b.ttid='IM_20110516_8711' ;
    The sub query -
    " SELECT key, perceivedseverity, eventtime, nvl(rate,'NA') rate FROM tr_alarm_history a
    WHERE eventtime = (SELECT MAX(eventtime) FROM tr_alarm_history WHERE key = a.key) "
    returns all records including RATE=NULLs. But when I join them, RATE columns with NULL will be filtered. Please note that joining condition (WHERE a.key = b.localtargetname) is not a problem as they will always match irrespective of RATE having NULL.
    Please let me know why this behaviour and is there any other alternative where in I can get the records even if RATE column is NULL.
    Thanks a lot for your help.
    -Anand

    I am extreemly sorry. 2 or 3 examples I took were wrong one's, which were not having RATE=NULL. So I got into such confusion.
    PLEASE INORE MY QUESTION.
    And thanks for your valuable time.
    With Best Wishes,
    -Anand

  • Xmlgen.getxml("select * from table") returns null pointer exception

    I am running oracle 8i on solaris server and clinet on windows
    NT and i am this select statement
    select xmlgen.getxml("select * from table") from dual ,its
    returning null pointer exception,i have tried it through
    jdbc,even then its returning xml as
    <?xml version = '1.0'?>
    <ERROR>java.lang.NullPointerException</ERROR>
    can any body tell me the error.Help will be really appreciated.I
    need an urgent response,if some one can guide me please.
    My email is [email protected],if you can give me a quick
    response on this email,your effot will be appreciated.
    thanks
    Masood

    What is actually throwing the NullPointerException? rs.getMetaData() or table.setModel()?

  • Select List not returning return_value

    Greetings
    I have a field on a page that is Display As: Select List.
    My list of values definition, (as generated by the Create Dynamic List of Values wizard)
    select DNAME display_value, DEPTNO return_value
    from DEPT
    order by 1
    When I run my page and select from the select list it returns the value of dname rather than deptno.
    Am I missing something, because of the format of the list of values definition I was expecting the return value of deptno.
    If I change my display type to PopupLOV, the return value is the deptno, so why is it that the select list is not returning deptno?
    Any help is appreciated
    Regards
    Mark

    Jeff,
    I read Mark's statement as saying:
    Select "Accounting" from select list
    Value returned displays "Accounting"
    Value stored in the database is "Accounting"
    which seems very odd. Whenever I've used these, it displays Accounting but the item value becomes "10".
    Good luck Mark!
    Stew

  • BufferedReader readLine() not returning null

    I'm trying write an SMTP client using Socket.
    I'm sending EHLO command to the SMTP server is is returning multiline response. When I tried to read this multiline response using the BufferedReader in a while loop, it is never returning null.
    Following is my code snippet
    while(true)
                    data=reader.readLine();
                    multilineData +=data+"\r\n";
                    if(data==null )
                        break;
                    }why it is not returning?

    I have written debug statements.
    It is printing the following lines and it still expecting something from the server even though server has finished sending all the response.
    250-mail.merakdemo.com Hello <hostname>, pleased to meet you.
    250-ENHANCEDSTATUSCODES
    250-SIZE
    250-EXPN
    250-ETRN
    250-ATRN
    250-DSN
    250-CHECKPOINT
    250-8BITMIME
    250-AUTH CRAM-MD5 DIGEST-MD5 LOGIN PLAIN
    250-AUTH=LOGIN
    250-STARTTLS
    250 HELP
    This is the end of response from server.
    And even I tried to break the while loop by checking the "HELP" String in the response. It is breaking the loop, but it is never returning the control.
    Following is the Code snippet:
    private String pullMultilineData(BufferedReader reader) throws CommunicationException
           String multilineData="";
           String data="";
            try
                while(true)
                    data=reader.readLine();
                    multilineData +=data+"\r\n";
                    // as per SMTP Protocol last line is without "-"
                    if(data==null || data.equals("") || data.indexOf("-")==-1)
                                        break;
                   logger.log(Level.DEBUG, "Data: "+data);
            catch(IOException ioe)
                logger.log(Level.ERROR, "I/O exception: "+ioe);
                throw new CommunicationException("unable to pull the respose, i/o error occured");
           return multilineData;
        }

  • 8i Query not returning expected records

    Using Oracle 8i (8.1.7), a basic spatial query is not returning all the expected results. Table1 contains a variety of polygons; table2 is simply a set of rectangles. I want to return all objects from table1 that intersect a particular rectangle. The query below mostly works, but misses out some objects. On my system, 38 objects are returned where about 41 are expected; on the client system (which does not have identical data) the problem appears to be much worse, with hardly any objects being returned. The missing objects are clearly visible on the map, surrounded on all sides by objects which have been selected correctly. Help?
    Select t1.id from table1 t1, table2 t2
    where t1.IsCurrent = -1
    and (sdo_relate(t1.geoloc, t2.geoloc, 'mask=ANYINTERACT querytype=WINDOW') = 'TRUE')
    AND (t2.ID in ('001'));

    Hi,
    When the non-spatial predicate is dropped, you mentioned the
    objects are not missing. This means the spatial index (which will
    surely be used in this case) should be returning correct results.
    But it is possible the index is not used when other predicates are
    specified. Please look at the "execution plan" in both cases (when the
    objects are missing/not missing).
    Rewrite the query as:
    select /*+ ORDERED INDEX(t1 <spatial_index_name>) */ t1.id from t2, t1
    This should ensure a spatial-index-based evaluation.
    Let us know the execution plans and the behavior in either case.
    Btw, one thing to check is your tolerance values in
    user_sdo_geom_metadata.
    - Ravi.

  • FDM for PBCS - Drill Thru does not return any records in landing page

    This is referring to the Data Management functionality in PBCS, not on-premise FDMEE.
    I loaded in a file, for example:
    Region|Product|Account|Amount
    10|100|1000|9,000
    10|100|1000|1,000
    In FDM, I am using a multi dimensional map to derive another field. For example, if Region is 10 and Product is 100, than Department = 555.
    so in FDM, I would end up with
    10|100|1000|555|9,000
    10|100|1000|555|1,000
    Once loaded to PBCS, that loads in as:
    10|100|1000|555|10,000
    I built a form that shows this intersection, and then 'drilled to source'. When I get to the FDM landing page, there are no records shown. Is this because the derived field (department) does not exist in the source, or am I doing something wrong?
    Appreciate any help.

    Do you have access to the server logs by any chance?
    Can you check the dimension class for your Scenario dimension in your target application? is it set to SCENARIO?
    not showing source records is typically related to FDMEE not finding values in TDATASEG table.
    HTH

  • SSRS 2012: How to get a "Select All" that returns NULL instead of an actual list of all values from a multi-select parameter?

    I have a multi-select parameter that can have a list of thousands of entries. In general, the user will pick a few entries from the list or "Select All". If they check "Select All", I would much prefer that I get a NULL or an empty string
    instead of a list of all values. Is there any way to do that?
    In experimenting with a work-around, I tried putting an "All" label with a null value in the list, but it is ignored (does not display in the drop-down). If I use an empty string for the value, my "All" entry does get displayed, but so
    does "Select All", which is confusing. Is there a way to suppress "Select All"?
    - Mark

    I adapted the following from a workaround posted by JNeo on 4/16/2010 at 11:14 AM at
    http://connect.microsoft.com/SQLServer/feedback/details/249227/multi-value-select-all-parameter-in-reporting-services
    To get a null value instead of the full list of all values when "Select All" is chosen:
    1) Add a multi-value parameter "MyParam" that lists the values to choose.
    2) Add a DataSet "ParamCount" identical to the one used by "MyParam", except that it returns a single column named [Count] that is a COUNT(*) of the same data
    3) Add a parameter "MyParamCount", set it to hidden and internal, then set the default value to 'Get values from a query', choosing "ParamCount" for the Dataset and the one [Count] column for the Value field.
    4) Change the parameter for the main report DataSet so that instead of using [@MyParam], it uses this expression:
    =IIF(Parameters!MyParam.Count =
    Parameters!ParamCount.Value, Nothing, Join(Parameters!MyParam.Value, ","))

  • Outer join not returning missing records.

    Hi All,
    Can you please look at the query and see why I don't get any record. There is no item '0141884' for cust_id '1259' in the nfpc_gpm_expense table.
    Thank you in advance.
    A/A
       SELECT DISTINCT rctla.customer_trx_id, msi.segment1 item_number,
                       rcta.trx_date trx_date, rcta.bill_to_customer_id cust_id,
                         (rctla.quantity_invoiced)
                       * NVL (msi.attribute13, 1) quantity,
                         rctla.unit_selling_price
                       * rctla.quantity_invoiced net_sales,
                       cic.material_cost * rctla.quantity_invoiced product_cost,
                         (rctla.unit_selling_price * rctla.quantity_invoiced
                       --  - (rctla.unit_selling_price * rctla.quantity_credited)
                       - (cic.material_cost * rctla.quantity_invoiced) gp_dollars,
                       nge.expense_amt
                  FROM ra_customer_trx_all rcta,
                       ra_customer_trx_lines_all rctla,
                       cst_cost_types cct,
                       cst_item_costs cic,
                       mtl_system_items_b msi,
                       nfpc_gpm_expense nge
              WHERE rcta.complete_flag = 'Y'
                   AND rcta.interface_header_attribute1 NOT LIKE '%B'
                   AND rcta.interface_header_context = 'ORDER ENTRY'
                   AND rcta.batch_source_id IN (1068, 1069)
                   AND rcta.customer_trx_id = rctla.customer_trx_id
                   AND rctla.inventory_item_id = msi.inventory_item_id
                   AND UPPER (cct.cost_type) = 'FROZEN'
                   AND cic.cost_type_id = cct.cost_type_id
                   AND cic.inventory_item_id = msi.inventory_item_id
                   and rcta.trx_date = '01-DEC-2009'
                  and msi.segment1 = '0141884'
                   and rcta.bill_to_customer_id = '1259'
                   and msi.segment1= nge.item_number(+)
                   and rctla.ATTRIBUTE1 = nge.DIVISION
                   and rcta.bill_to_customer_id = nge.CUST_ID
                  

    Table nfpc_gpm_expense is
      CUSTOMER_NO        VARCHAR2(20),
      ITEM_NUMBER        VARCHAR2(10),
      EXPENSE_AMT        VARCHAR2(20),
      DIVISION           VARCHAR2(20),
      INVENTORY_ITEM_ID  VARCHAR2(20),
      CUST_ID            VARCHAR2(20)Sample data in this table is
    CUSTOMER_NO     ITEM_NUMBER     EXPENSE_AMT     DIVISION     INVENTORY_ITEM_ID     CUST_ID
    02250000     0261884          1.76          B          8716               1259And this is the result of the query. Note that item 0141884 is missing from the result while as this item was sold on that day for this customer but since it is not in the nfpc_gpm_expense table, it doesn't show up.
    CUSTOMER_TRX_ID     ITEM_NUMBER     DIVISION     TRX_DATE     CUST_ID     QUANTITY     ORDER_NO     EXPENSE_AMT     NET_SALES     PRODUCT_COST     GP_DOLLARS     EXPENSE
    887617     0261884     B     12/1/2009     1259     60     1047572     1.76     662.4     338.4     324     105.6Edited by: asgar_amin on Mar 5, 2010 12:46 PM

Maybe you are looking for

  • Understanding A/P credit memo

    Hi everyone, I have some transactions as the following: 1. Goods Receipt PO No. 1 ItemCode_______________________ItemCost_______Quantity M001G0A001NAC0030020_________1,235,205.44_______300 M001G0A001NAC0055020_________1,680,397.84_______400 M001G0A00

  • SAP PI 7.1 HTTP Adapter

    In my scenario, SAP PI 7.1. needs to talk to a 3rd party EDI system via web services. SAP PI is using HTTP adapter to exchange XML messages for both inbound and outbound with the EDI system. Questions: 1. If SAPI PI sends for example 100 (different)

  • Cost elemts and  company code

    Dear Experts, is there any sap std report avb to display cost elements for one company code when same controlling area is assigned to several company codes? i.e. list of cost elements for company codes wise. or else any alternative? Regards babu

  • My iPhone 4 has been overheated all this week

    My iPhone has been overheated all this week, and making rare sounds..what should I do?.

  • "Compiler error. Report this problem to NI." LV7.0

    I get the error "Compiler error. Report this problem to NI; nmx unbundler bad sea/eea or edisp-sdisp=0x4". I generated a test vi, where you can reproduce the error. The error happens, when saving or running the vi. This kind of error is happening in