开发者

overwriting arguments in t-sql functions

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 app开发者_C百科ears 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..)


The @date you're working with here is local to your function. You'll change the value within the function but not affect the value in the calling code.


Function must be declare with a return value/type and last statment must be a return statement. If your last statment returns @date then Getdate() value will be returned.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜