Home Forums SQL Server 2012 SQL Server 2012 - T-SQL What is wrong with this syntax? Query will work, but CTE will not "compile" RE: What is wrong with this syntax? Query will work, but CTE will not "compile"

  • Eirikur Eiriksson (4/27/2014)


    Jeff Moden (4/27/2014)


    Eirikur Eiriksson (4/8/2014)


    hisakimatama (4/8/2014)


    Aha, so it doesn't :-). I've always declared CTEs with the column declarations, and by the wonderful problems of habit, it stuck as "the" way to do it. Well, I learned something that should make syntax a good bit clearer myself 😀

    I prefer it, makes the code more readable.

    😎

    I've found just the opposite to be true if there are a ton of columns being returned by the CTE. I'd just as soon write it as a good and proper encapsulated SELECT and let the defintion of the CTE be simple.

    But, to each their own! I even change my ways when I'm working for a different company and they say how they want it done. 😛

    Let me rephrase it, I prefer it, when it makes the code more readable:-P

    I usually make sure to name all the columns in the select list but there are times when I define the list of columns separately but not sure when or why. I have actually gotten away from it since working with Oracle for a year as the subquery refactoring clause doesn't support the definition of the column names upfront.