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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Select Query with column name containing [] [Figured out]

Select Query with column name containing [] [Figured out]

Scheduled Pinned Locked Moved Database
databasesql-serversysadmintutorialquestion
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.
  • D Offline
    D Offline
    dan sh
    wrote on last edited by
    #1

    I have a columns say, Col and Col[1] in table say Test. Now I want to do a select from it. How to go about it? (Since [] has a special meaning for SQl server) I tried

    select Col,Col[1] from Test

    but for obvious reasons, it does not works. [Edit] This will work:

    Select Col,[Col[1]]] from Test

    [/Edit]

    50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!

    modified on Thursday, December 17, 2009 12:59 AM

    M 1 Reply Last reply
    0
    • D dan sh

      I have a columns say, Col and Col[1] in table say Test. Now I want to do a select from it. How to go about it? (Since [] has a special meaning for SQl server) I tried

      select Col,Col[1] from Test

      but for obvious reasons, it does not works. [Edit] This will work:

      Select Col,[Col[1]]] from Test

      [/Edit]

      50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!

      modified on Thursday, December 17, 2009 12:59 AM

      M Offline
      M Offline
      Mycroft Holmes
      wrote on last edited by
      #2

      try

      select Col,[Col[1]] from Test

      Who would be dumb enough to use reserved words or characters in a column name. Stoopid really.

      Never underestimate the power of human stupidity RAH

      D 1 Reply Last reply
      0
      • M Mycroft Holmes

        try

        select Col,[Col[1]] from Test

        Who would be dumb enough to use reserved words or characters in a column name. Stoopid really.

        Never underestimate the power of human stupidity RAH

        D Offline
        D Offline
        dan sh
        wrote on last edited by
        #3

        Mycroft Holmes wrote:

        Who would be dumb enough to use reserved words or characters in a column name.

        Well, I just did that to find how SQL will behave.

        50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!

        M 1 Reply Last reply
        0
        • D dan sh

          Mycroft Holmes wrote:

          Who would be dumb enough to use reserved words or characters in a column name.

          Well, I just did that to find how SQL will behave.

          50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!

          M Offline
          M Offline
          Mycroft Holmes
          wrote on last edited by
          #4

          Did not even look at the moniker before answering otherwise I'd have been questioning your sanity. Doing that is akin to sticking your finger in the power point, may not kill you but your fingers gonna sting for a while. So did the extra set of brackets work? I flatly refuse to try it out

          Never underestimate the power of human stupidity RAH

          D 1 Reply Last reply
          0
          • M Mycroft Holmes

            Did not even look at the moniker before answering otherwise I'd have been questioning your sanity. Doing that is akin to sticking your finger in the power point, may not kill you but your fingers gonna sting for a while. So did the extra set of brackets work? I flatly refuse to try it out

            Never underestimate the power of human stupidity RAH

            D Offline
            D Offline
            dan sh
            wrote on last edited by
            #5

            Mycroft Holmes wrote:

            Doing that is akin to sticking your finger in the power point, may not kill you but your fingers gonna sting for a while.

            :laugh: Never tried this.

            Mycroft Holmes wrote:

            So did the extra set of brackets work?

            Yes it did.

            50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!

            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