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

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -