Question

I am currently using SQL Server Management Studio (Ver 9.00.3042.00) and click the "New Query" and wrote the following code:

Select 
    colA,
    colB,
    colC
    colD
From
    table1

When I click the parse (checkbox) button to validate the SQL statement, it says "Command(s) completed successfully". Isn't the parse button suppose to catch these simple errors...

Has anyone experienced this type of behavior from Management Studio? This just started happening this week....

Was it helpful?

Solution

That's because that is valid SQL. You're effectively aliasing colC with the name colD. It's the same as typing:

colC as colD

Edit: For what it's worth, this is one of the reasons why people will argue that you should put the commas at the beginning of the line in cases like this. It's a lot easier to spot gotchas like this when the code is formatted as such:

Select 
    colA
    , colB
    , colC
    colD
From
    table1

OTHER TIPS

After a little playing around, it throws the "Incorrect syntax near" on the following code snippets

Select     
    colA,    
    colB    
    colC    
    colD
From    
    table1

Select     
    colA,    
    colB,    
    colC,    
    colD,
From    
    table1
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top