Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. sql conctante first name and last name

sql conctante first name and last name

Scheduled Pinned Locked Moved Database
databasehelptutorial
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    netJP12L
    wrote on last edited by
    #1

    Hi guys I have two fields, FirstName and LastName. I am able to concatnate both names but if one of the name is null then I don't get the results. For example, First name is John and there is no last name then upon concatanting both names i get null. I have set the database "Concatenate Null yeilds Null" to True but still no success. Perhaps, could anyone of you help me. Thanks

    I A C 3 Replies Last reply
    0
    • N netJP12L

      Hi guys I have two fields, FirstName and LastName. I am able to concatnate both names but if one of the name is null then I don't get the results. For example, First name is John and there is no last name then upon concatanting both names i get null. I have set the database "Concatenate Null yeilds Null" to True but still no success. Perhaps, could anyone of you help me. Thanks

      I Offline
      I Offline
      i j russell
      wrote on last edited by
      #2

      Have a look at COALESCE.

      1 Reply Last reply
      0
      • N netJP12L

        Hi guys I have two fields, FirstName and LastName. I am able to concatnate both names but if one of the name is null then I don't get the results. For example, First name is John and there is no last name then upon concatanting both names i get null. I have set the database "Concatenate Null yeilds Null" to True but still no success. Perhaps, could anyone of you help me. Thanks

        A Offline
        A Offline
        Avi Berger
        wrote on last edited by
        #3

        netJP12L wrote:

        First name is John and there is no last name then upon concatanting both names i get null.

        netJP12L wrote:

        I have set the database "Concatenate Null yeilds Null" to True

        It sounds like this is doing exactly what you told it to. You could: 1) follow i.j.russell's suggestion and use COALESCE, [edit - added] 2) try changing the setting, 3) write code that tests for Null and handles the various cases, or 4) don't allow Null values in these fields. Looking through the list, i.j.russell's suggestion sounds very good to me.

        Please do not read this signature.

        1 Reply Last reply
        0
        • N netJP12L

          Hi guys I have two fields, FirstName and LastName. I am able to concatnate both names but if one of the name is null then I don't get the results. For example, First name is John and there is no last name then upon concatanting both names i get null. I have set the database "Concatenate Null yeilds Null" to True but still no success. Perhaps, could anyone of you help me. Thanks

          C Offline
          C Offline
          Corporal Agarn
          wrote on last edited by
          #4

          For MS SQL Server I use ISNULL like ISNULL(FirstName + ' ', '') + ISNULL(LastName, '') I put a space after the first name but if it is null then the space does not get added.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups