Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
GunnerMcGrath
Starting Member
1 Post |
Posted - 2008-10-23 : 13:38:03
|
| Hi all, just a simple question about the generally accepted way to write a bit of SQL.When specifying a new column name for calculated columns, I know there are many syntaxes that will work, all with the same result. It seems that the most common is as follows:SELECT col1 , col2 , col1 + col2 AS SumColumnsFROM tableNow personally, I don't like doing it this way because when you have very large computations, subqueries, case statements, etc., it puts your column name at the end of the statement which makes it hard to know what you're looking at until you search for the column name, especially if you're selecting dozens of columns.My personal preference was to write it like this:SELECT col1 , col2 , "SumColumns" = col1 + col2FROM tableThis puts the column name at the front where it's easy to see, and the double quotes aren't used anywhere else in my SQL so I always know double quotes means a column name.At my new job, they've demanded I not use double quotes due to their SQL standards here. They said I can use single quotes, or no quotes at all, which both work. Unfortunately both of these styles are misleading because it could be read to mean that those are either strings or already-existing column names.Just curious if anyone else has some input on a nice way to write my queries now that I've been forbidden from using double quotes. It's all in subjective but I'd like to hear a few opinions and find out if there's a generally accepted way to do this.On the other hand, if you can give me a good reason why their "no-double-quotes" rule for SQL is stupid so I can argue them out of it, that would be just as good =) |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
|
|
|
|
|