SQL Server : computed column error in dateadd formula -
these columns (simplifying):
mydate date themonths int
then create computed column finaldate
in microsoft sql server management studio 2008 r2, formula:
(dateadd(month, themonths, mydate))
very simple. there error:
error validating formula
the error occurs if insert formula through integrated assistant in management studio. not occurs when create column through t-sql query.
if change mydate
type datetime
, there's no error, can't change table structure.
i try this:
(dateadd(month, themonths, convert(datetime, mydate)))
the error persists.
i created column directly in t-sql using following:
add [finaldate] (dateadd(month,[themonths],[mydate])) persisted
it works fine, column created, data computed when insert-update. problem in management studio.
try 1 -
create table dbo.[test] ( mydate date not null default (getdate()), themonths int not null default ((0)), finaldate (dateadd(month, themonths, mydate)) persisted ) insert dbo.[test] (mydate, themonths) values('20130101', 5) select * dbo.[test]
Comments
Post a Comment