It''s funny but interesting

  • I have a column "4Blocker_Date" in Table TempTab.

    When I execute "Select * from TempTab"

    It returns me all columns with all records of TempTab table.

    But whenI try execute follwing query

    "Select Distinct 4Blocker_Date From TempTab"

    The above query returns only one record with value as "4".SQL server considering it as  4 as value and Blocker_date is aliyas name for that column but in TempTab I have column as a 4Blocker_Date and above query is not selecting values from 4Blocker_Date column.

     

  • Try:

    Select Distinct [4Blocker_Date]

    From TempTab

    And in the future, avoid using numeric characters at the beginning of column names... As you can see, SQL Server does not like it

    --
    Adam Machanic
    whoisactive

  • It's not that strange. '4Blocker_Date' is an invalid name as it begins with a number, so I'm not surprised it behaves "funny".

    What happens if you execute "Select Distinct [4Blocker_Date] From TempTab" ?

    /Kenneth

  • One might think, that when SQL Server doesn't like, why did it let the table obviously get created at all? Isn't that the original error here?

     

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

  • Not really, imo the original error is (well, by all means imho the fact that you are allowed to use square brackets is the 'true' blame) - but... the original error is on the creator of the column in the first place.

    Once you use square brackets, you must continue to always use square brackets.. You simply can't create a table with a columnname like '4Blocker_Date' without bracketing the name like [4Blocker_Date]. If you try, SQL Server will flatly deny to create such a table.

    The problem with using these is that you may unknowingly create invalid names that later cause all kinds of problems, since square bracketing let's you do just that - stuff you should not do..

    /Kenneth

  • the original error is on the creator of the column in the first place

    Allow for something, and sooner or later someone smart will do it. No matter if intentionally or not.

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

Viewing 6 posts - 1 through 5 (of 5 total)

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