overwriting arguments in t-sql functions

Posted by chuck taylor on Stack Overflow See other posts from Stack Overflow or by chuck taylor
Published on 2011-01-10T20:47:45Z Indexed on 2011/01/10 20:54 UTC
Read the original article Hit count: 149

Filed under:

I was playing around with some code and realized that it is possible to overwrite the argument to a t-sql function. i.e.,

create function someFn(@date date) as
begin
if @date is null set @date = getdate()

will set @date to be today's date if the argument was null.

This appears only to make any sense if t-sql is treating their arguments as references not values. I realized that I don't actually know what the t-sql rules are for cases like this and was hoping someone could elaborate what is going on here. (I don't ever recall seeing any value vs. reference discussion with respect to t-sql code for that matter actually..)

© Stack Overflow or respective owner

Related posts about tsql