Adding 2 field together for a max character length

Answered Adding 2 field together for a max character length

  • Friday, May 11, 2012 10:07 PM
     
     

    In SQL how do I add 2 fields together for max char length.

    I have a field 25 char max.

    I want to add Field A  (last name) + ', ' + B (First name)

    But I need to trim the first name for a maa 25 total character allowed.  Some people's last name are too long so the field ends up getting a binary string error so I want to avoid this by just trimming the first name field.

    How do I do this please?

All Replies

  • Friday, May 11, 2012 10:14 PM
    Moderator
     
     Answered

    Use the LEFT function

    LEFT( last name + ', ' + First name,25)

    • Marked As Answer by CIWorker Friday, May 11, 2012 10:33 PM
    •  
  • Friday, May 11, 2012 10:26 PM
     
     

    What's wrong with the substring function?


    Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se