sql server - Can I declare a local variable not null? -
in t-sql, declare local variable use query so:
declare @var_last datetime; set @var_last = (select top(1) col_date tbl_dates order col_date);
in application i'm testing, error query return null, , it's desirable query return crash error if were.
i'd set @var_last
not null
syntax...
declare @var_last datetime not null;
...is invalid. can write simple check on return of query see if it's null, , error if is, question is, not possible declare local variable not null?
that's right, according documentation declare @local_variable
, available at: http://technet.microsoft.com/en-us/library/ms188927.aspx, doesn't accept null | not null
parameter -- valid column definitions.
if want stop execution if return null
, test null
and, if is, raiserror
; see: http://technet.microsoft.com/en-us/library/ms178592.aspx.
Comments
Post a Comment