Raghavendra Mudugal (8/19/2014)
Thank you, Tom, very interesting one.
As the old saying goes "everything has pros and cons", so any one see the "pros" side of it?
(I am kind of feeling now, its one of the stupid question from me)
The pro is of course that if you put all the declarations combined with assignment in a non-repeated part of the stored procedure, trigger, or batch the assignments get executed exactly once, so the net effect is much the same as declaration with initialisation to a chosen value and this can quite useful for making the code easier to read (it reduces clutter).
Something that is often claimed as a plus for this is that it eliminates the possibility of uninitialised variables, but that's pure nonsense. It doesn't have the effect that adding initialisation to declarations in some other languages, specifically languages which have variable declarations without initialisation, since (scalar) variable declarations in T-SQL initialise the variable to NULL anyway: there no such thing as an uninitialised variable in T-SQL; thus the claim that it eliminates the uninitialised variable problem from T-SQL (which I've seen rather too often) is nonsense, don't be fooled into thinking that that imaginary effect is a plus of allowing combined declaration and assignment syntax as an abbreviation for a declaration plus a set statement.