I want to create a computed column.
I have a table say Table 1 that has a column called as Date of Joining.
I want to create a column that will return the value in Months(int) by subtracting the today date and the [Date of Joining] column.
I used this: (datediff(month,[DateJoining],getdate()))
And it works perfectly well but i dont know why the computed type column is of null
type even i made DateJoining column of not null type
Any help is highly Appreciated.
I can’t tell you why SQL Server behaves this way, nor do I understand why it matters other than for understanding (which you won’t really get because I don’t know if anyone here can explain why this is the case). I think for an int it may be guarding against overflow (even though that is clearly not possible in this case).
If you really want the system catalog to confirm for you that the column is not nullable:
NB: This trick won’t work with
COALESCE.