29

I tried the following statement but failed with compile error. declare @myValue int NULL

2
  • I don't see any compile error... hint, hint
    – musefan
    Jan 5, 2015 at 10:07
  • All local (scalar) variables are nullable. Jan 5, 2015 at 10:24

2 Answers 2

44

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

23

Your syntax is wrong. By default all variables are nullable

 declare @myValue int=NULL

OUTPUT

 select @myValue
 NULL

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.