Concatenate fields with no values

Ask a Question related to Coldfusion Database Access, Design and Development.

  1. #1

    Default Concatenate fields with no values

    I am running CF 5 with SQL Server 2000. I am looking to concatenate a person
    name, but not all names have a suffix or middle name.

    Sample SQL:
    SELECT ID, Last_name + N' ' + Suffix + N', ' + First_Name + N' ' +
    Middle_Name AS Full_Name
    FROM tTable
    ORDER BY ID

    The problem is when someone does not have a suffix. The value of Full_Name
    will then look like "Doe , John M." with an extra space after the last name.
    Can I put in an IF statement in my SQL? This problem must be handled in the
    SQL. Normally I would take care of this with CF code during the query output.

    Pubcit Guest

  2. Similar Questions and Discussions

    1. Add values of two fields
      Good day, I just want to know if it is possible using developers toolbox to sum values of two fields (field1 + field2 =field3) where field3 is the...
    2. Can you concatenate recordset values in one field?
      Hi I have an Access db which stores, amongst other things, details of small mailing lists, people who have received a particular mailing. Because...
    3. Concatenate Fields to >255 chars
      "Peter" <peter@somewhereontheinter.net> wrote in news:cuds3o$b3d$1@forums.macromedia.com: Hi Peter, Are you using cfinsert/cfupdate - or a...
    4. Concatenate column values from multiple rows
      Greetings, Would it be possible to construct SQL to concatenate column values from multiple rows? SELECT ... FROM T1, T2 WHERE T1.key=T2.fkey...
    5. concatenate text fields
      Does anyone know of a workaround to concatenate text fields???? thanks, jr
  3. #2

    Default Re: Concatenate fields with no values

    Try using CASE ....

    SELECT Last_name + CASE Suffix WHEN '' THEN N'' ELSE N' '+ Suffix END .....
    FROM tTable
    ORDER BY ID

    Or if the Suffix values are NULL (and not an empty string), you could also use
    the COALESCE() function.

    mxstu Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139