SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2004
    Location
    griffith
    Posts
    72
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    If/then statement for null value

    I am displaying last name, first name in a table. For null values, I need to display Not Given rather than blank spaces separated by a comma. How do I deal with two fields in an if/then statement?

  2. #2
    Afrika
    Join Date
    Jul 2004
    Location
    Nigeria
    Posts
    1,737
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    create a recordset in ASP.

    Then using the recordset do a response.write
    <%=
    If (recordset_name.Fields.Item("f_name").Value) <> "" then
    response.write(recordset_name.Fields.Item("f_name").Value)
    else response.write("Not Given")
    end if
    %>

    however i would advice that you put an on error resume next statement in the recordet instatiation and a statement saying
    if not recordset_name.eof and not recordset_name.bof then ....'do something

    else you might get an error

    Afrika

  3. #3
    Original Gangster silver trophy Thing's Avatar
    Join Date
    Oct 2000
    Location
    Philadelphia, PA
    Posts
    4,708
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Keep in mind that "" and NULL are two seperate things. So you would format to check for both like this:

    Code:
    If IsNull(recordset_name("f_name")) = false AND recordset_name("f_name") <> "" then
    'do whatever
    Else
    response.write "Not Given"
    End if

  4. #4
    Afrika
    Join Date
    Jul 2004
    Location
    Nigeria
    Posts
    1,737
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    My mistake.

    Actually big mistake.

    It didnt occur to me cos this is ASP forum.

    Afrika

  5. #5
    Afrika
    Join Date
    Jul 2004
    Location
    Nigeria
    Posts
    1,737
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ...but if u do a select statement and its eof (end of file) and you do use the on error resume next code, it probably would work the same way.

    Afrika

  6. #6
    SitePoint Enthusiast
    Join Date
    Nov 2004
    Location
    griffith
    Posts
    72
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code worked. Much thanks. I have a few fields to which teh null and empty values apply. Anyway to set the code up so it looks at all the fields and applies the rule? Right now I am copying the code into each field to address the nulls.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •