SQR vs Text

  • Hi all

    I've seen some of my coworkers naming their columns with text and some with sqr brackets. Thus the reason for the question, which one of the 2 statements is beter, I've always used sqr brackets. So i thought it would be intressting to know what the diff are if any and hear some of the other members views and opinions

    SELECT

    0 AS 'Coumn with funny $chars *!@#$%^&*()'

    SELECT

    1 AS [Coumn with funny $chars *!@#$%^&*()]

     

    ,cheers l0n3i200n

  • I don't know the difference between the two but I use them interchangeably.

    I also use [] brackets for badly named (mostly Access style) columns like [Order Numbers]


    Everything you can imagine is real.

  • There are ways to cause problems with each based on really bad column names, but [] may be less likely to have this problem.

    Ex. 1, Breaking Single quotes

    1) select 1 as 'Bob's Column' --Fix is adding another quote

    2)  select 1 as [Bob's Column] --Works

    Ex. 2, Breaking Brackets

    1) select 1 as 'Ugly [] Column' --Works

    2) select 1 as [Ugly [] Column] --Doesn't Work

    Another thought is that brackets are easier to standardize.  You can use them for tables, whereas single quotes, you cannot.  Consistency is a good thing, in my opinion.

    Ex. 3

    1)  select 1 as [Test], * from [sysobjects] --No comments on my choice of table!

    2) select 1 as 'Test', * from 'sysobjects' --Does not work...

    So there you go, a couple things to think about.  BTW, I would recommend never using brackets, quotes or keywords in schema, at any rate...

    Thanks,

    Eric

     

  • Good point Eric. I always use brackets but in your case  "select 1 as [Ugly [] Column] --Doesn't Work" it would make much more sense to use text.

    l0n3i200n

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply