Results 1 to 3 of 3

Thread: Concatenating new field makes everthing disappear

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    May 2004
    Location
    South Charleston, WV, USA
    Posts
    607

    Concatenating new field makes everthing disappear

    The following works in reading from my SQL Server table:

    Code:
            Dim CMD As New SqlCommand
            CMD.Connection = conn
    
            CMD.CommandText = "SELECT tblPersons.id, "
            CMD.CommandText = CMD.CommandText & "CASE "
            CMD.CommandText = CMD.CommandText & "WHEN gobyn IS NULL "
            CMD.CommandText = CMD.CommandText & "THEN fn "
            CMD.CommandText = CMD.CommandText & "ELSE gobyn "
            CMD.CommandText = CMD.CommandText & "END "
            CMD.CommandText = CMD.CommandText & "+ ' ' + ln "
            CMD.CommandText = CMD.CommandText & "FROM tblPersons ORDER BY "
            CMD.CommandText = CMD.CommandText & "tblPersons.ln, tblPersons.gobyn, tblPersons.fn, tblPersons.suffix"
    But when I add a field called suffix, all the records which don't have anything in that field come up blank.

    Code:
            Dim CMD As New SqlCommand
            CMD.Connection = conn
    
            CMD.CommandText = "SELECT tblPersons.id, "
            CMD.CommandText = CMD.CommandText & "CASE "
            CMD.CommandText = CMD.CommandText & "WHEN gobyn IS NULL "
            CMD.CommandText = CMD.CommandText & "THEN fn "
            CMD.CommandText = CMD.CommandText & "ELSE gobyn "
            CMD.CommandText = CMD.CommandText & "END "
            CMD.CommandText = CMD.CommandText & "+ ' ' + ln + suffix "   '<--add the field here        CMD.CommandText = CMD.CommandText & "FROM tblPersons ORDER BY "
            CMD.CommandText = CMD.CommandText & "tblPersons.ln, tblPersons.gobyn, tblPersons.fn, tblPersons.suffix"
    How can I correct this? The whole name,suffix included, does appear correctly when there is a value in suffix. The rest of the records are blank. Take out siffix and it's fine (except no suffix).

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Concatenating new field makes everthing disappear

    It sounds like suffix is not actually blank (ie: a string with no characters), but Null (ie: does not even exist, the value is basically "unknown at this time").

    When you append a Null to something, it is logically impossible to deduce what the final value should actually be, so the database system makes the overall result equal to Null.

    There are various ways for you to specify what should be done instead, such as a Case similar to what you used for gobyn.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    May 2004
    Location
    South Charleston, WV, USA
    Posts
    607

    Re: Concatenating new field makes everthing disappear

    Then I would have to do that for fn and ln, too. Ugh! You don't have to test every field when you concatenate in Access.
    Last edited by projecttoday; Apr 25th, 2010 at 05:21 AM.

Posting Permissions

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



Click Here to Expand Forum to Full Width