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. & or + to join fields/text?

& or + to join fields/text?

Scheduled Pinned Locked Moved Database
performancequestion
7 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.
  • M Offline
    M Offline
    myNameIsRon
    wrote on last edited by
    #1

    Hi, Please refresh my memory... What the difference is between using & or + to join fields with text. SELECT FirstName + ' ' + LastName AS FullName FROM table or SELECT FirstName & ' ' & LastName AS FullName FROM table thanks, Ron

    A S 2 Replies Last reply
    0
    • M myNameIsRon

      Hi, Please refresh my memory... What the difference is between using & or + to join fields with text. SELECT FirstName + ' ' + LastName AS FullName FROM table or SELECT FirstName & ' ' & LastName AS FullName FROM table thanks, Ron

      A Offline
      A Offline
      Ashfield
      wrote on last edited by
      #2

      myNameIsRon wrote:

      SELECT FirstName + ' ' + LastName AS FullName FROM table

      This works

      myNameIsRon wrote:

      SELECT FirstName & ' ' & LastName AS FullName FROM table

      This doesn't, you get Invalid operator for data type. Operator equals boolean AND, type equals varchar.

      Bob Ashfield Consultants Ltd

      M 1 Reply Last reply
      0
      • A Ashfield

        myNameIsRon wrote:

        SELECT FirstName + ' ' + LastName AS FullName FROM table

        This works

        myNameIsRon wrote:

        SELECT FirstName & ' ' & LastName AS FullName FROM table

        This doesn't, you get Invalid operator for data type. Operator equals boolean AND, type equals varchar.

        Bob Ashfield Consultants Ltd

        M Offline
        M Offline
        myNameIsRon
        wrote on last edited by
        #3

        Hmmm, Both will work for me. I'm using a MS Access db with OleDbCommand (C#) Ron

        M A M 3 Replies Last reply
        0
        • M myNameIsRon

          Hmmm, Both will work for me. I'm using a MS Access db with OleDbCommand (C#) Ron

          M Offline
          M Offline
          Michael Potter
          wrote on last edited by
          #4

          Both do not work on SQL Server. Access has its own brand of SQL and does a lot of wierd stuff.

          1 Reply Last reply
          0
          • M myNameIsRon

            Hmmm, Both will work for me. I'm using a MS Access db with OleDbCommand (C#) Ron

            A Offline
            A Offline
            Ashfield
            wrote on last edited by
            #5

            My mistake, I assumed you were using SQL Server - or maybe yours for not specifying :) Anyway, as Micheal has said, Access has its own rules!

            Bob Ashfield Consultants Ltd

            1 Reply Last reply
            0
            • M myNameIsRon

              Hmmm, Both will work for me. I'm using a MS Access db with OleDbCommand (C#) Ron

              M Offline
              M Offline
              myNameIsRon
              wrote on last edited by
              #6

              Thanks guys, I didn't realize it was specific to Access SQL. I did some testing, and here it is. If your field is NULL, and you're using '+', the join is ignored. SELECT ID_Field + ' - ' & NameField FROM table ID_Field not null: 3433 - Bob Smith ID_Field null: Bob Smith SELECT ID_Field & ' - ' & NameField FROM table ID_Field not null: 3433 - Bob Smith ID_Field null: - Bob Smith Ron

              1 Reply Last reply
              0
              • M myNameIsRon

                Hi, Please refresh my memory... What the difference is between using & or + to join fields with text. SELECT FirstName + ' ' + LastName AS FullName FROM table or SELECT FirstName & ' ' & LastName AS FullName FROM table thanks, Ron

                S Offline
                S Offline
                Sgg245
                wrote on last edited by
                #7

                + return NULL if any one of the field contains NULL value. Otherwise both more or less returns same results. :)

                Regards SG

                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