Where condition to test for null

Hi,
I have a query where we were thinking that 2 fields will not have null values even though column allows nulls. So, wrote a query like this:
select.......
From table 1 left outer join table2 on (table1.name = 'I' and table2.accountnum in (table1.creditact, table1.debitact).
Now I need to check for null if table1.creditact and table1.debitact. If both fields are null, then I have to use third column to check because out of 3 column (creditact, debitact, act) one must have account number. How can I do it.
Thanks,
Spunny

I have a query where we were thinking that 2 fields [sic: columns are not fields] will not have NULL values [sic: NULL is not a value] even though column allows NULLs. So, wrote a query like this:
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. What you did post implies that your design is wrong. Did you actually have debits and credits as separate attributes in RDBMS? No, surely not! I will guess, based 30+ years of SQL, that you have a crappy design
with too many NULLs. 
Would you like to obey the Netiquette so we can actually help you, or you do just want a Kludge? 
--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

Similar Messages

  • Test for null result set

    I am trying to do a test for a null result set. Basically if the result set returns a value I want to display a table, otherwise I want to display an error message. The following code does not produce the error message. Either the test for null is incorrect, or for some reason I am not getting a null result set even when I don't enter any text into the following text boxes (this is for a login screen, these text boxes come a login screen):
    <input type="text" name="username">
    <input type="text" name="password">
    This is the code for the action page:
    <HTML>
    <%@page import="java.sql.*"%>
    <%
    //define connection
    Connection con = null;
    String user1 = request.getParameter("username");
    String pass1 = request.getParameter("password");
    String test = "good";
    try{
    //get the class
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    //get the connection
    con = DriverManager.getConnection("jdbc:odbc:errorlog", "admin", "");
    //catch your exceptions!
    catch(Exception e){
         out.println(e.getMessage());
    %>
    <title>Error Application - Logged Errors</title>
    <link href="style/errorstyle.css" rel="stylesheet" type="text/css">
    <BODY>
    <%
    //define resultset and statement
    ResultSet rs=null;
    Statement stmt=null;
    try {
    //Using the current database connection create a statement
    stmt=con.createStatement();
    %>
    <%
    String sql="SELECT* FROM tblUsers" + " WHERE Username = '"+user1+"' AND Password ='"+pass1+"'";
    rs = stmt.executeQuery(sql);
    %>
    <% //Fetch all the records and print in table
    while(rs.next()){
    String user2 = rs.getString("FirstName");
    String pass2 = rs.getString("LastName");
    %>
    <table width="100%" border="0" cellspacing="1" cellpadding="6">
    <tr >
    <td width="67" height="27" bgcolor="#999999"><strong><font size="- 1">First Name</font></strong>
    </td>
    <td width="89" bgcolor="#999999"><strong><font size="-1">Last
    Name</font></strong>
    </td>
    </tr>
    <tr>
    <td>
    <%out.println(user2);%>
    </td>
    <td><%out.println(pass2);%></td>
    </table>
    <%}
    if (rs == null)
    out.println("Incorrect Username or Password");
    //close all your open resultsets, statements, and connection when you are done with them!
    rs.close();
    stmt.close();
    con.close();
    //catch all your exceptions
    catch (SQLException e) {
         out.println(e.getMessage());
    %>

    You simply test the rs.next().
    if ( rs.next() )
    //spit out the rs row and
    //continue processing the resultset 'til empty
    else
    msg = "invalid username or password
    }

  • Condition to test for the browser closing/refreshing

    I have an applet that rotates pictures in a html file. I have it in an eternal loop to keep it running. It loads fine, but if you refresh or try to close the browser, the browser locks. Without question this happens because the loop does not test for the browser closing or refreshing so the loop never stops. Does anyone have an idea of a Java condition to test for the browser closing/refreshing so I can stop my loop when these events occur.

    The applets stop message should be called on a reload and/or a close. You could set a flag in your stop method that could be checked by a thread that actually sits and loops.
    When the flag is set, kill the tread.
    You should clear that flag in your start method.
    I have an applet that rotates pictures in a html file.
    I have it in an eternal loop to keep it running. It
    loads fine, but if you refresh or try to close the
    browser, the browser locks. Without question this
    happens because the loop does not test for the
    browser closing or refreshing so the loop never
    stops. Does anyone have an idea of a Java condition
    to test for the browser closing/refreshing so I can
    stop my loop when these events occur.

  • Dropdown List Value Test For Null || " "

         I wrote a pre-sign script to test a for a value in a dropdown list before allowing signature of the document. However I want to test for a value of null in addtion to one space aka " ". I added a value in the dropdown list of " " along with the choices of names so users could erase an accidental selection in this list before they were ready. However when I place the or ( || ) operator in the if statement of the script the script doesn't work. If I remove the || " " statement the script works as it is supposed to. How do I test for this value of " " along with the null test so I don't have to write another if statement?
    if (form1.Page3.Author.Reviewed.Admin.rawValue == null || " ")
    xfa.event.cancelAction = 1
    xfa.host.messageBox("You did not select your name on the dropdown list before trying sign the document .");
    else

    Your if statement is incomplete. You need to put the test in again for the other value:
    if (form1.Page3.Author.Reviewed.Admin.rawValue == null || form1.Page3.Author.Reviewed.Admin.rawValue == " ")

  • How to pass where condition to report for condition

    hello people ,
    i want to pass where condition for the report statement .
    for example ,
    select ename from emp
    i want to pass parameter carry <where deptno=40>
    thanks

    Good Morning oracleuser,
    If we understood correctly, Bind references (or bind variables) should use this issue.
    a>select ename from emp where deptno= :Dept_Number
    If you have any more questions, please post it.
    Otherwise:
    Mark Helpful or Answer accordingly.

  • JSTL Core - How to test for null?

    How do I test an attribute for null using JSLT's if statement? The below code does not work (the JSTL if statement does not return true). The scriptlet however does work and displays the statement.
    - Chris
    index.jsp
    <%@ taglib uri="c.tld" prefix="c"%>
    <%@ taglib uri="fmt.tld" prefix="fmt"%>
    <%@page import="java.util.*"%>
    <%
       request.setAttribute("null", null);
    %>
    <html>
    <head>
      <title>JSTL Test Page</title>
    </head>
    <body>
    <c:if test="${null}==null">
    The value was null (JSTL)
    </c:if>
    <%
      if (request.getAttribute("null")==null) out.print("The value was null (Scriptlet)");
    %>
    </body>
    </html>
    <%out.flush();%>

    Well, I figured out. If anyone is interested, here is the code:
    <c:if test="${empty varName}">
      Its null
    </c:if>

  • Trying to test for null input

    I am trying to get some input from a user using:
    String name="";       
    BufferedReader in = new BufferedReader(
        new InputStreamReader(System.in));
    name = in.readLine();Let's say the user inputs nothing other than the enter key, how can I test for this so that I can write output for it?
    In Python, one would use something like:
    if not name:
         <then do something>Thanks,
    Harlin Seritt

    Thanks for the help. When I try it with an empty
    string test, nothing happens. However, the test of
    name.length() works perfectly. Thanks!
    Harlin SerittI'm guessing you tried this, right?
    if (name == "") ...
    That's not the way to compare string values. The == operator only compares object references when comparing 2 objects. It's an extremely common mistake.

  • Query of queries testing for null or empty dates

    I'm having problems with this query (within a function). The
    last condition in the where clause needs to check for an empty or
    null date and then check against the current date (which is fine),
    im aware that the syntax is wrong but wondered if someone could
    correct it for me to get it working.
    <cfquery name="filterQuery" dbtype="query"
    maxrows="#arguments.top#">
    select * from getAllSaved
    where
    workFlowStatusId = <cfqueryparam
    cfsqltype="CF_SQL_INTEGER"
    value="#application.const.WORKFLOW_LIVE#" />
    and
    dateArchive > <cfqueryparam cfsqltype="CF_SQL_DATE"
    value="#now()#" />
    and
    dateLive <= <cfqueryparam cfsqltype="CF_SQL_DATE"
    value="#now()#" />
    and
    (dateExpiry is null or dateExpiry = '') or dateExpiry >
    <cfqueryparam cfsqltype="CF_SQL_DATE" value="#now()#" />
    </cfquery>

    I feel stupid, although i'd put a fiver on having tried that!
    thanks

  • Beginner question - testing for null string from shell script command

    I'm trying to test the result of a shell script command. I want to put out a message if the result is a null string. At present I get this applescript error "The command exited with a non-zero status"
    I'm sure this is a simple question ... but I can't figure out how to do it. Help!

    You can use try clause for the problem:
    set _result to ""
    try
    set _result to do shell script "/blah/andblah"
    end

  • Can you really use Display String formula to test for NULL

    I am trying to manipulate the Display String of a field throught the Format Editor.  If a field is null, it should display "N/A", or "No data given", or anything else appropriate I might choose.
    I can't get this feature to work and I'm wondering if there's a bug here.  I'm using the following formula:
    if (isnull() or    trim() = "")
    then "N/A"
        else
    Am I doing something wrong or is there a better way to do this?

    Hi Adriane
    The other way to display "N/A", or "No data given" if a field is null is using a formula with if -else statement as follows:
    whileprinting records;
    if (isnull() or trim () =" ")
    then "N/A"
    else
    Please let me know if this helps.
    Thanks
    Poonam Thorat

  • For all entries Where condition character length partilally has to be used

    Hi,
    I need to fetch all the data reocrds of one internal table into the other with the condition that in one of the field of first internal table only partial length of the character has to be used as a where condition.
    Example:
    Select xxxx
              yyyyy
              zzzzz
    into it_tab2
    for all entries in itab1
    where field2 = itab1-field1(4).
    where field1 of itab1 has length of 8 and field2 belongs to itab2.
    As it throws the error msg :
    it will ignore the length restriction mentioned in where condition of the for all entries

    Hi.
    If you are trying to fetch from any database table based on your modified table use this logic.
    Dfine another internal table same as itab1, with field one lenght as 4 char.
    ex:
    data: begin of it_tab2.
            field1(4),
    end of it_tab2.
    loop at it_tab1.
    it_tab2 = itab1+0(4).
    append it_tab2.
    clear it_tab2.
    endloop.
    now you can fetch from database table....using it_tab2.
    Select xxxx
    yyyyy
    zzzzz
    into it_tab3
    for all entries in itab2
    where field2 = itab2-field1(4).
    If you only want to move the entries form one internal table to another internal table and truncate the field1 of itab1.
    then no need to use any for all entries...
    apply this logic
    data: begin of it_tab2.
            field1(4),
    end of it_tab2.
    loop at it_tab1.
    it_tab2 = itab1+0(4).
    append it_tab2.
    clear it_tab2.
    endloop.
    Regards,
    Satish

  • Conditional actions in Photoshop can't test for Lab color mode.

    I’m posting here because the feature request/bug report form isn’t currently working for Photoshop.
    I wanted to create an action to determine if the color mode of an image is Lab, and if so, convert it to RGB. But there’s no conditional action test for Lab color mode.  The list of conditions that can be tested includes RGB, grayscale, and a couple of other color modes, but not Lab,  Does anyone know of a workaround?  Can I get it done with scripting?
    It would be a big help if the next update of Photoshop CC could include a conditional action test for Lab color mode.

    This for example would convert an active Lab image to sRGB:
    if (app.documents.length > 0) {
    if (app.activeDocument.mode == DocumentMode.LAB) {
    app.activeDocument.convertProfile ("sRGB IEC61966-2.1", Intent.RELATIVECOLORIMETRIC, true, true);

  • Searching for NULL with a FindPanel?

    Can I search for null values in my dataset using the FindPanel
    InfoBus control?
    From what I can gather, it actually puts together a primitive
    kind of where clause that I can trick to a certain extent (eg
    entering a criteria of "ANY (value, value,...)" to simulate an IN
    clause - because it will prepend the criteria with an equals
    sign), BUT I can't get it to find NULL values, which requires the
    IS NULL operator.
    Lachlan
    null

    We've found a workaround, which is ugly, but works.
    In the FindPanel, to successfully search for nulls, you can enter
    a combination of two conditions joined with an OR operator. For
    example, to search for members in the ACME_MEMBERS table with a
    null MID_INITIAL, I could enter the condition:
    = 'XXX' OR MID_INITIAL is null
    and then the WHERE clause will be:
    WHERE MID_INITIAL = 'XXX' OR MID_INITIAL is null
    which will find the rows I'm looking for.
    BUT, this is REALLY ugly, and there should be a better way.
    If anyone knows of a better way, please let me know.
    Lachlan
    Lachlan Williams (guest) wrote:
    : I am assuming that the FindPanel will call the associated
    : DataItem's setQueryCondition and then actually execute the
    query
    : for me, all happening when I press the Find button.
    : I can't see where in this paradigm there is an opportunity to
    : alter the where clause.
    : So to rephrase my original question: how can I explicitly test
    : for null values using the existing functionality of the
    FindPanel
    : control? (ie how do I get the IS NULL operator into the where
    : clause?).
    : Thanks,
    : Lachlan
    : JDeveloper Team (guest) wrote:
    : : Hi
    : : The FindPanel relies on RowSetInfo 's setQueryCondition. you
    : can
    : : try to directly use this method to set the query condition.
    : : regards
    : : Lachlan Williams (guest) wrote:
    : : : Can I search for null values in my dataset using the
    : FindPanel
    : : : InfoBus control?
    : : : From what I can gather, it actually puts together a
    primitive
    : : : kind of where clause that I can trick to a certain extent
    (eg
    : : : entering a criteria of "ANY (value, value,...)" to simulate
    : an
    : : IN
    : : : clause - because it will prepend the criteria with an
    equals
    : : : sign), BUT I can't get it to find NULL values, which
    requires
    : : the
    : : : IS NULL operator.
    : : : Lachlan
    null

  • How to check for null values in bpel?? Please Help! very urgent!!!

    Hello Guys,
    I have a problem. I have an external webservice to which I have to post my request. My task is to create an Webservice and Service Assembly to which others would post request and get response. I have to create SA to deploy onto the bus.
    The problem is that there are optional elements in the request and response xsd's. In the Response sometimes certain feilds may come or they may not. for Example:- my response could contain a tag like this <firstName></firstName>
    I have to copy these feilds in my bpel process from one variable to another.(like in the mapper).
    My Question is , Is there any way in BPEL process or BPEL mapper where I could Check for null values in the request or response???
    Your inputs would be very helpful.
    Thanks
    Rajesh

    Thanks for replying man :)
    Ok I will be more clear.
    Here is a snippet of one of the xsd's that I am using.
    <xs:element name="returnUrl" nillable="false" minOccurs="0">
                        <xs:annotation>
                             <xs:documentation>Partner specifies the return URL to which responses need to be sent to, in case of
    Async message model.
    </xs:documentation>
                        </xs:annotation>
                        <xs:simpleType>
                             <xs:restriction base="xs:anyURI">
                                  <xs:maxLength value="300"/>
                                  <xs:whiteSpace value="collapse"/>
                             </xs:restriction>
                        </xs:simpleType>
                   </xs:element>
    This means that the return URL field can be there or it may not be there. But if it is there it cant be null because nillable=false. But the whole <returnURL> </returnURL> can be there or it may not be there because minOccurs=0.
    My requirement is , if returnURL is there in the response with a value, then in my BPEL mapper I should map it else I should not map it.
    Thats the issue.
    and Yes kiran, the node be non-existant.
    So can you please help me with this.
    Thanks
    Rajesh

  • Testing for IS NOT NULL with left join tables

    Dear Experts,
    The query is showing the NULL rows in the query below....
    Any ideas, advice please? tx, sandra
    This is the sql inspector:
    SELECT O100321.FULL_NAME_LFMI, O100321.ID, O100404.ID, O100321.ID_SOURCE
    , O100404.NAME, O100321.PERSON_UID, O100404.PERSON_UID, O100404.VISA_TYPE
    FROM ODSMGR.PERSON O100321
    , ODSMGR.VISA O100404
    WHERE ( ( O100321.PERSON_UID = O100404.PERSON_UID(+) ) ) AND ( O100404.VISA_TYPE(+) IS NOT NULL )

    Hi Everyone,
    I am understanding alot of what Michael and Rod wrote.... I am just puzzled over the following:
    the query below is left joining the STUDENT table to
    HOLD table.
    The HOLD table - contains rows for students who have holds on their record.
    a student can have more than one hold (health, HIPAA, basic life saving course)
    BUT, for this query: I'm only interested that a hold exists, so I'm choosing MAX on hold desc.
    Selecting a MAX, helps me, bec. it reduces my join to a 1 to 1 relationship, instead of
    1 to many relationship.
    Before I posted this thread at all, the LEFT JOIN below testing for IS NOT NULL worked w/o
    me having to code IS NOT NULL twice....
    Is that because, what's happening "behind the scenes" is that a temporary table containing all max rows is being
    created, for which Discoverer has no predefined join instructions, so it's letting me do a LEFT JOIN and have
    the IS NOT NULL condition.
    I would so appreciate clarification. I have a meeting on Tues, for which I have to explain LEFT JOINS to the user
    and how they should create a query. I need to come up with rules.
    If I feel "clear", I asked my boss to buy Camtasia videocast software to create a training clip for user to follow.
    Also, if any Banner user would like me to email the DIS query to run on their machine, I would be glad to do so.
    thx sooo much, Sandra
    SELECT O100384.ACADEMIC_PERIOD, O100255.ID, O100384.ID, O100255.NAME, O100384.NAME, O100255.PERSON_UID, O100384.PERSON_UID, MAX(O100255.HOLD_DESC)
    FROM ODSMGR.HOLD O100255, ODSMGR.STUDENT O100384
    WHERE ( ( O100384.PERSON_UID = O100255.PERSON_UID(+) ) ) AND ( O100384.ACADEMIC_PERIOD = '200820' )
    GROUP BY O100384.ACADEMIC_PERIOD, O100255.ID, O100384.ID, O100255.NAME, O100384.NAME, O100255.PERSON_UID, O100384.PERSON_UID
    HAVING ( ( MAX(O100255.HOLD_DESC(+)) ) IS NOT NULL )
    ORDER BY O100384.NAME ASC

Maybe you are looking for

  • GR Date for Delivery Schedule line

    Vendor On-Time Delivery Report We have vendor On-Time Delivery report requirement, where we rate the goods-delivery of a vendor as "On-Time" or "Early" or "Late". The rating is given based on the difference between "Statistical Delivery date" and "GR

  • Scroll bar does not scroll far enough to view last page in thumbnail images

    When using Adobe Acrobat, and have the thumbnails/pages panel open on the left side, the scroll bar will not scroll far enough down to show the last row of thumbnails. For example, have a 40-page document open with the Pages Panel open showing page t

  • Deploying ADF 11.1.2.3 to WLS 11.1.1.6

    I see in the release notes that two patches are required to the ADF Runtime to bring it to 11.1.2.3 when deploying to WLS 11.1.1.6: http://www.oracle.com/technetwork/developer-tools/jdev/11gr2update3-1851251.html#11.1.2.3.0ShermanUpdate3-ReleaseNotes

  • Comment écrire en plusieurs colonnes dans Write to spreadsheet?

    Bonjour, J'ai plusieurs  données à récupérer, mais mon problème n'est pas dans l'écriture du fichier mais plutôt les écrire en colonne dans le fichier. J'ai deux  boucles imbriquées, une qui va prendre les données et les écrire dans un fichier , et l

  • Desktop Manager shuts down without prompt in the middle of sync

    Hello All, My desktop manager shuts down without prompt in the middle of sync without an error message.  Each time I sync I have to reopen it mutiple times before a sync in completed.  Has anyone else experieced this BB 8830 Windows XP OS