0

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..)

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.