I tried the following statement but failed with compile error.
declare @myValue int NULL
The rule for assigning NULL values to variables or table columns is simple: Use keyword "NULL" directly as normal values. Specificly, "NULL" can be used in SET statements to assign NULL values to variables.
If the value of expression is NULL, IS NULL returns TRUE; otherwise, it returns FALSE. If the value of expression is NULL, IS NOT NULL returns FALSE; otherwise, it returns TRUE.
You can use this query, to set the specific row on a specific column to null this way: Update myTable set MyColumn = NULL where Field = Condition. Here, the above code will set the specific cell to null as per the inner question (i.e. To clear the value from a cell and make it NULL).
If you are trying to make the variable as NOT NULL
variable which will not accept any NULL
values then I don't think it is possible.
MSDN says
After declaration, all variables are initialized as
NULL
, unless a value is provided as part of the declaration
so you don't have to mention it explicitly
Your syntax is wrong. By default all variables are nullable
declare @myValue int=NULL
OUTPUT
select @myValue
NULL
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With