0

I have function that returns a Date value. I need to assign that return value to a declared variable.

Declare @Duedate Date
Set @Duedate = SELECT dbo.TATDueDateCaluator('2019-05-10',2)
Select @Duedate

Msg 156, Level 15, State 1, Line 2 Incorrect syntax near the keyword 'SELECT'.

3 Answers 3

2

If the function is scalar valued you don't even need a SELECT. Just

SET @duedate = dbo.tatduedatecaluator('2019-05-10', 2);

should do.

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

1 Comment

Thanks for the answer. ;)
2

You can assign directly in a SELECT:

Declare @Duedate Date;

SELECT @DueDate = dbo.TATDueDateCaluator('2019-05-10', 2);

Select @Duedate;

Your code doesn't work because subqueries always need their own parentheses.

3 Comments

Thanks for the answer. I have doubt is this Set the value to the variable or not? Because we usually to assign a value by using SET Variable_name = Value. Right?
@SanjithM . . . Yes, this sets the variable.
Thanks @Gordon Linoff.
0

You can simply define it in one line:

Declare @Duedate Date = dbo.TATDueDateCaluator('2019-05-10',2)

Select Duedate

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.