Professional Web Applications Themes

Concatenate fields with no values - Coldfusion Database Access

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 ...

  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. #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

Similar Threads

  1. Add values of two fields
    By fryon in forum Macromedia Exchange Dreamweaver Extensions
    Replies: 3
    Last Post: December 11th, 10:11 AM
  2. Adding values from various fields..
    By Martijn in forum Coldfusion Database Access
    Replies: 0
    Last Post: November 14th, 08:56 PM
  3. Can you concatenate recordset values in one field?
    By tim-p in forum Dreamweaver AppDev
    Replies: 5
    Last Post: April 21st, 09:06 PM
  4. Concatenate Fields to >255 chars
    By Simon Dallmair in forum Coldfusion Database Access
    Replies: 0
    Last Post: March 18th, 10:47 AM
  5. concatenate text fields
    By jr in forum Microsoft SQL / MS SQL Server
    Replies: 1
    Last Post: July 8th, 02:22 PM

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
  •  

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