Home Forums SQL Server 2005 Development is there away of using a computed column in another computed column formular in sql server 2005 RE: is there away of using a computed column in another computed column formular in sql server 2005

  • Run this query and note the anomalies in the results:

    SELECT DateEngaged,MonthsInService As 'YearsinService',DATEDIFF(Month,DateEngaged,GETDATE()) AS 'Months Dif'

    ,DATEDIFF(Month,DateEngaged,GETDATE())/12 AS 'Pseudo Years'

    ,MonthsInService*2 AS 'MyColumn3' FROM dbo.MyComputedColumn ORDER BY DateEngaged

    DateEngagedYearsinServiceMonths DifPseudo YearsMyColumn3

    1990-03-01 00:00:00.00020 238 19 40

    1990-04-01 00:00:00.00020 237 19 40

    1990-05-01 00:00:00.00020 236 19 40

    1990-05-01 00:00:00.00020 236 19 40

    2000-05-01 00:00:00.00010 116 9 20

    2009-12-01 00:00:00.0001 1 0 2

    2010-01-12 00:00:00.0000 0 0 0

    Without thinking of the inconsistencies in the results calculated MyColumn3 could be performed in the T-SQL select statement, no need for a second computed column.

    If everything seems to be going well, you have obviously overlooked something.

    Ron

    Please help us, help you -before posting a question please read[/url]
    Before posting a performance problem please read[/url]