How to declare a null local variable in t-sql?

I tried the following instruction, but could not compile the error.    declare @myValue int NULL

+4
source share
2 answers

If you are trying to make a variable a variable NOT NULLthat does not take any values NULL, then I do not think that this is possible.

MSDN says

After the declaration, all variables are initialized as NULLif only the value is provided as part of the declaration

therefore you do not need to mention it explicitly

+12
source

Your syntax is incorrect. By default, all variables are NULL

 declare @myValue int=NULL

OUTPUT

 select @myValue
 NULL
+6
source

Source: https://habr.com/ru/post/1569970/


All Articles