Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Sql server computed field Expand / Collapse
Author
Message
Posted Friday, January 22, 2010 12:48 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Monday, March 26, 2012 5:05 AM
Points: 16, Visits: 136

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.
Post #851782
Posted Friday, January 22, 2010 2:12 AM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 4:54 PM
Points: 42,434, Visits: 35,488
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 2008, MVP
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass

Post #851831
Posted Friday, January 22, 2010 2:27 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Monday, March 26, 2012 5:05 AM
Points: 16, Visits: 136
giving an error message (Incorrect syntax near the keyword 'AS')
Post #851840
Posted Friday, January 22, 2010 2:32 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Monday, March 26, 2012 5:05 AM
Points: 16, Visits: 136
giving an error message (Incorrect syntax near the keyword 'AS')
Post #851843
Posted Friday, January 22, 2010 3:03 AM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 4:54 PM
Points: 42,434, Visits: 35,488
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 2008, MVP
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass

Post #851861
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse