I want to alter a view as follows:
ALTER VIEW [dbo].[ViewOne] as
SELECT columnOne, -- not null
columnTwo, --not null
(convert(decimal(2,0), columnOne)) as columnThree -- I want this not to be NULL
FROM DBOne.TableOne
Since columnOne is “not null” I want to force columnThree to be “not null” also.
Is is possible, impossible, implicit, useless or could cause serious problems since columnOne is char(2) populated with algarisms only.
I simply would like to know the syntax
ColumnThree will never be null if the source of the Cast is itself never null. However, that does not mean you will not get an exception if ColumnOne cannot be cast to
decimal(2,0)and you will not know whether you will get an exception until you query against the view. You should consider adding an additional check to determine whether the cast will fail and help mitigate the possibility of a cast error: