Wednesday, May 30, 2012

SELECTing to make your queries more robust...

FatherJack - TSQL formatting - a sure fire way to start a conversation.

There are probably as many opinions on ways to format code as there are people writing code and I am not here to say that any one is better than any other. Well, that isn't true. I am here to say that one way is better than another but this isn't a matter of preference or personal taste, this is an example of where sloppy formatting can cause TSQL to weird and whacky things but following some simple methods can make your code more reliable and more robust when .

Take these two pieces of code, ready to run against your regular, vanilla AdventureWorks database



By using these two simple methods you can be more confidant that a change to TSQL wont result in a broken view, function or procedure and therefore anything like SQL Agent jobs or SSRS reports that rely on those objects will also function as and when expected.


While I'm not a fan of table aliases (not sure why, but I'd rather use the full table name... less mental runtime translation I guess) this article has me re-thinking that a little. If they not only shorten the T-SQL coding but can also add query time validation like this, that's something to consider. Hum....

No comments: