Wrox Home  
Search P2P Archive for: Go

  Return to Index  

sql_language thread: SQL 2000 age old question, Using birthdate to calculate age


Message #1 by "Bonnie James" <wytmagic@h...> on Thu, 10 Jan 2002 10:09:02
Beginner here. I have hunted all over the web and only managed to piece 
the available data together and get this far in SQL Server 2000 SQL Query 
Analyzer:

---Begin My Code--
DECLARE @BirthDate SMALLDATETIME, @Age SMALLDATETIME
SELECT @BirthDate = [BirthDate]FROM [portal].[dbo].[Users]
SELECT @Age = GETDATE()
SELECT DATEDIFF(YY,@BirthDate,@Age) -
    CASE WHEN (MONTH(@BirthDate) = MONTH(@Age) AND DAY(@BirthDate) > DAY
(@Age)
    OR MONTH(@BirthDate) > MONTH(@Age))
    THEN 1 ELSE 0 END AS Age
--End My Code--

I was amazed when the query actually ran and returned the proper value 
under an "Age" Header. 

My trouble is how do I get the result to update the [Age] field in the 
same DB [portal].[dbo].[Users]? I Have tried the several tactics and 
failed at all. Again, I am a beginner, so other obvious questions are:

Can this even be done?
Am I totally off-base in trying to use a SQL Query?
If I am off-base, what should I be trying to use?
Any help and/or leads will be appreciated.

Thank-you,
Bonnie

  Return to Index