January 22, 2010 at 12:48 am
Create table #Test
(
emp_id int
emp_Birth_Date
emp_Age int AS datediff(d,emp_Birth_Date, getdate())
)
....this computed field cannot work....i need the field to automatically calculate the differece and retains number as results.....any help.
thanks.
January 22, 2010 at 2:12 am
What do you mean by 'cannot work'? Is it giving an error? Is it not giving the values you want? Something else?
Calculated columns are not stored, they're calculated when the column is queried.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
January 22, 2010 at 2:27 am
giving an error message (Incorrect syntax near the keyword 'AS')
January 22, 2010 at 2:32 am
giving an error message (Incorrect syntax near the keyword 'AS')
January 22, 2010 at 3:03 am
You don't specify a data type when creating a computed column. The data type depends on the result of the expression.
Create table #Test (
emp_id int,
emp_Birth_Date DATETIME,
emp_Age AS datediff(d,emp_Birth_Date, getdate())
)
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply