Column name assignment

  • Sean Lange - Monday, August 28, 2017 9:15 AM

    Steve Jones - SSC Editor - Monday, August 28, 2017 8:56 AM

    I don't like that it's deprecated, as I like to see all the column names on the left, but I understand this can be confusing. I would prefer if they remove this they allow:

    select
      'FullName'  for  firstname + lastname,
       CustomerID
      from Customers

    To be fair Steve it is ONLY the single quotes portion that has been deprecated. It isn't needed and causes confusion IMHO.

    This is  still perfectly legal.


    select
        FullName = firstname + lastname
        , CustomerID
    from Customers

    That's right. only left hand assignment with single or double quote is deprecated.

  • drew.allen - Monday, August 28, 2017 9:40 AM

    Sean Lange - Monday, August 28, 2017 9:15 AM

    Steve Jones - SSC Editor - Monday, August 28, 2017 8:56 AM

    I don't like that it's deprecated, as I like to see all the column names on the left, but I understand this can be confusing. I would prefer if they remove this they allow:

    select
      'FullName'  for  firstname + lastname,
       CustomerID
      from Customers

    To be fair Steve it is ONLY the single quotes portion that has been deprecated. It isn't needed and causes confusion IMHO.

    This is  still perfectly legal.


    select
        FullName = firstname + lastname
        , CustomerID
    from Customers

    I wish they would deprecate using single quotes in a column alias at all.  I see that <expression> [AS] 'column_alias' has not been deprecated.  I generally do not use delimiters in my column aliases unless required and I only ever use the square brackets [] as the delimiters.

    Drew

    I agree Drew. I find seeing SomeColumn as 'SomeColumnAlias' can be quite confusing. Especially for newer people, it gets easy to confuse an alias with a string literal.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

  • Avi1 - Monday, August 28, 2017 9:55 AM

    Sean Lange - Monday, August 28, 2017 9:15 AM

    Steve Jones - SSC Editor - Monday, August 28, 2017 8:56 AM

    I don't like that it's deprecated, as I like to see all the column names on the left, but I understand this can be confusing. I would prefer if they remove this they allow:

    select
      'FullName'  for  firstname + lastname,
       CustomerID
      from Customers

    To be fair Steve it is ONLY the single quotes portion that has been deprecated. It isn't needed and causes confusion IMHO.

    This is  still perfectly legal.


    select
        FullName = firstname + lastname
        , CustomerID
    from Customers

    That's right. only left hand assignment with single or double quote is deprecated.

    There's no need to introduce a new keyword "for", and doing so would be crazy because it would certainly cause problems for anyone with a column called "for" (as well as for anyone using the deprecated construct); just replace the quote marks around the column name by "[" and "]" (select [1/0] = 'Hello'; isn't deprecated - at least not yet).   And of course replacing "FullName" by "1/0" doesn't work - some names need their boundaries to be marked.

    But given how often MS uses "backwards compatability" as an excuse for not corecting blatant errors in its system I seems rather stange that they have chosen deprecate the use of quote marks to do this - that is deliberately destroying backward compatability for no known reason except somebody's whim.   If people have code that uses it this change will kill that code until someone fixes it.

    Tom

  • This was removed by the editor as SPAM

Viewing 4 posts - 16 through 18 (of 18 total)

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