Concatenate First Name and Last Name fields into Full Name field

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Zubair Mughal
    New Member
    • Sep 2020
    • 3

    Concatenate First Name and Last Name fields into Full Name field

    I have 3 fields in my Staff database.
    First Name;
    Last Name;
    Full Name.

    I want to Concatenate First Name and Last Name fields to STORE/SAVE in Full Name fields at frmStaff on tblStaff.
  • Nauticalgent
    New Member
    • Oct 2015
    • 103

    #2
    Hello there!

    Easy to do, but I would suggest NEVER storing concatenated data. It is a better practice to do this for Forms, Reports, and Queries - but not in a table. What if the name changes, or if you make a mistake and have to change it?

    Anyway, to answer your question:

    [First Name] & " " & [Last Name]

    - or -

    [Last Name] & ", " & [First Name]

    Again, I strongly urge you to not do this at the table level...

    Comment

    • twinnyfo
      Recognized Expert Moderator Specialist
      • Nov 2011
      • 3653

      #3
      Zubair,

      Welcome to Bytes!

      I will echo what Nauticalgent suggests and refrain from having this as a field within a Table. There is really no reason/need to have a field with this concatenated Full Name. If you ever need to display the full name, just concatenate it at run time--either within your Query, Form or Report. This has to do with basic, good DB design of avoiding the duplication of data. For small datasets, this doesn't matter in the overall scheme of things, but at Bytes, we prefer to guide you down the "right" path, and not just a path that will solve your temporary problem while creating others.

      Hope this hepps!

      Comment

      • Zubair Mughal
        New Member
        • Sep 2020
        • 3

        #4
        I much appreciated for your Right Path to do concatenate Full Name at Table level.Thanking you.

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32634

          #5
          I'm not sure if you're misunderstandin g or mis-expressing what the others have said.

          DON'T store the concatenated field in a table! Create it as and when you need it from the basic data that is already available from [First Name] & [Last Name].

          This is very easy to do in a Query for instance as :
          Code:
          SELECT [First Name]
               , [Last Name]
               , [Last Name] & (', '+[First Name]) AS [FullName]
          FROM   [tblStaff]
          Notice the use of the + character for string concatenation with Null propagation. Also notice the use of the correct SQL standard quotes (') for when working in SQL as opposed to the double-quotes (") as used in VBA. Jet/ACE is very forgiving and supports both, but that can leave you with complications down the line if you rely on that.

          Comment

          • AjayGohil
            New Member
            • Apr 2019
            • 83

            #6
            No point of doing this. You can get Full-Name using Firstname and Lastname whenever you need. You don't nedd to store full name in database.If you ever change Firstname or Lastname then Fullname become outdated. when you need to display Full Name, just concate the two of them. Do not Repeat Data in your Database.

            "select concat(firstnam e,' ',lastname) as name from users";

            Comment

            • twinnyfo
              Recognized Expert Moderator Specialist
              • Nov 2011
              • 3653

              #7
              Ajay,

              Yes, you have restated what others have already stated, but you also included a Concat() function that does not exist natively in Access (it does exist in mySQL and SQL server). If you would like to post your version of code to declare such a function in MS Access VBA, that is certainly welcome here, as this would be a useful function--or you can create a new thread/article describing this User-Defined function.

              Thanks!

              Comment

              Working...