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. I'm trying to concat 2 columns into a single result

I'm trying to concat 2 columns into a single result

Scheduled Pinned Locked Moved Database
5 Posts 2 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.
  • J Offline
    J Offline
    jkirkerx
    wrote on last edited by
    #1

    SELECT
    Label
    , (SELECT BFirstName, BLastName FROM CARDINFOPERM WHERE CardID = 1121) AS BAttention
    , BCity
    FROM CardInfoPerm
    WHERE CardID = 1121

    J 1 Reply Last reply
    0
    • J jkirkerx

      SELECT
      Label
      , (SELECT BFirstName, BLastName FROM CARDINFOPERM WHERE CardID = 1121) AS BAttention
      , BCity
      FROM CardInfoPerm
      WHERE CardID = 1121

      J Offline
      J Offline
      jkirkerx
      wrote on last edited by
      #2

      Perhaps

      (SELECT CONCAT(BFirstName, ' ', BLastName) FROM CARDINFOPERM WHERE CardID = 1121) AS BAttention

      This works, not sure if it's safe
      (SELECT CONCAT(BFirstName, ' ', BLastName)) AS BAttention

      S 1 Reply Last reply
      0
      • J jkirkerx

        Perhaps

        (SELECT CONCAT(BFirstName, ' ', BLastName) FROM CARDINFOPERM WHERE CardID = 1121) AS BAttention

        This works, not sure if it's safe
        (SELECT CONCAT(BFirstName, ' ', BLastName)) AS BAttention

        S Offline
        S Offline
        Sascha Lefevre
        wrote on last edited by
        #3

        Since it's the same table you can just write it like this:

        SELECT
        Label
        , CONCAT(BFirstName, ' ', BLastName) AS BAttention
        , BCity
        FROM CardInfoPerm
        WHERE CardID = 1121

        jkirkerx wrote:

        not sure if it's safe

        If you're thinking about null-values:

        Quote:

        Null values are implicitly converted to an empty string. If all the arguments are null, an empty string of type varchar(1) is returned.

        (From https://msdn.microsoft.com/en-us/library/hh231515.aspx[^]) So you might want to surround the CONCAT(..) with a TRIM(..).

        If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson

        J 1 Reply Last reply
        0
        • S Sascha Lefevre

          Since it's the same table you can just write it like this:

          SELECT
          Label
          , CONCAT(BFirstName, ' ', BLastName) AS BAttention
          , BCity
          FROM CardInfoPerm
          WHERE CardID = 1121

          jkirkerx wrote:

          not sure if it's safe

          If you're thinking about null-values:

          Quote:

          Null values are implicitly converted to an empty string. If all the arguments are null, an empty string of type varchar(1) is returned.

          (From https://msdn.microsoft.com/en-us/library/hh231515.aspx[^]) So you might want to surround the CONCAT(..) with a TRIM(..).

          If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson

          J Offline
          J Offline
          jkirkerx
          wrote on last edited by
          #4

          Cool Thanks for the quick help Sascha!

          S 1 Reply Last reply
          0
          • J jkirkerx

            Cool Thanks for the quick help Sascha!

            S Offline
            S Offline
            Sascha Lefevre
            wrote on last edited by
            #5

            You're welcome! :)

            If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson

            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