Hi,
I think there is some confusion in the documentation about the assignment of variables by select within declaration.
First it is written here it is not possible, but in next examples the assignment by select is used when showing other limitations.
So I would like to ask, is it possible to assign variable by select within declare statement? Thanks.
⚠Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
Thank you for your detailed feedback. We are looking into the issue, and we will respond when we have more information.
Thank you for bringing this to our attention, @SmallTomas .
I believe what it means to say is "You cannot use DECLARE inside a SELECT statement or inside an UPDATE statement. Also, UPDATE cannot be used to change the variable value.
I base this idea on three points:
I will assign this to the author @XiaoyuMSFT for clarification and correction.
@SmallTomas - Thank you for your feedback. The last code example should be changed to:
DECLARE @p1 int = 0;
DECLARE @p2 int = (SELECT COUNT (*) FROM sys.types where is_user_defined = @p1 );