Check for Null

Discussion in 'ASP General' started by Luis, Sep 7, 2004.

  1. Luis

    Luis Guest

    Is there an easier way to check if any of the fields returned in a
    select statement have null values?

    After running this command:

    set rs = conn.execute("select A,B,C,D,E,F,G,H,I,J from SomeTable
    where...")

    I could check each field this way:

    If IsNull(rs("A") Then
    Response.Write("The value of A is null")
    Else
    Response.Write("The value of A is " & rs("A"))
    End If

    If IsNull(rs("B") Then
    Response.Write("The value of B is null")
    Else
    Response.Write("The value of B is " & rs("B"))
    End If

    If IsNull(rs("C") Then
    Response.Write("The value of C is null")
    Else
    Response.Write("The value of C is " & rs("C"))
    End If

    etc.

    But is there a simpler way?

    Also, my "solution" probably wouldn't work if more than one recordset
    was returned...


    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    Luis, Sep 7, 2004
    #1
    1. Advertising

  2. Luis

    Thomas Dodds Guest

    use a null replacement in your SQL statement - I don't kow what DB you are
    working with...

    an oracle example: set rs = conn.execute("select NVL(A,'IsNull') AS A, ...
    from SomeTable where...")
    an SQL server example: set rs = conn.execute("select ISNULL(A,'IsNull') AS
    A, ... from SomeTable where...")


    "Luis" <> wrote in message
    news:u1pSX%...
    > Is there an easier way to check if any of the fields returned in a
    > select statement have null values?
    >
    > After running this command:
    >
    > set rs = conn.execute("select A,B,C,D,E,F,G,H,I,J from SomeTable
    > where...")
    >
    > I could check each field this way:
    >
    > If IsNull(rs("A") Then
    > Response.Write("The value of A is null")
    > Else
    > Response.Write("The value of A is " & rs("A"))
    > End If
    >
    > If IsNull(rs("B") Then
    > Response.Write("The value of B is null")
    > Else
    > Response.Write("The value of B is " & rs("B"))
    > End If
    >
    > If IsNull(rs("C") Then
    > Response.Write("The value of C is null")
    > Else
    > Response.Write("The value of C is " & rs("C"))
    > End If
    >
    > etc.
    >
    > But is there a simpler way?
    >
    > Also, my "solution" probably wouldn't work if more than one recordset
    > was returned...
    >
    >
    > *** Sent via Developersdex http://www.developersdex.com ***
    > Don't just participate in USENET...get rewarded for it!
     
    Thomas Dodds, Sep 7, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kivak Wolf
    Replies:
    2
    Views:
    10,095
    Kivak Wolf
    Jun 28, 2005
  2. vizlab
    Replies:
    3
    Views:
    4,233
    Michael Bar-Sinai
    Oct 17, 2007
  3. Replies:
    5
    Views:
    26,910
    Mike Schilling
    Mar 29, 2006
  4. G Fernandes
    Replies:
    9
    Views:
    608
    DHOLLINGSWORTH2
    Feb 27, 2005
  5. Mike
    Replies:
    12
    Views:
    730
    Daniel Pitts
    Sep 26, 2008
Loading...

Share This Page