Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
rhall47
Starting Member
2 Posts |
Posted - 2011-09-02 : 14:37:32
|
| Hello, I'm new here but desperately need your help. I'm trying to put together a simple script to update a database table with a Rubgy Clubs Junior Team assignment.Each player has a record with the Date of Birth and the team that he has been assigned to based upon his age at the 1st September 2011. I have the beginings of the script but I'm not sure if you can use 'IF' statements that calculate the number of years:-DECLARE @TARGETDATE smalldatetimeDECLARE @AGE intUPDATE [Membership].[dbo].[Juniors]SET @TARGETDATE = '2011-09-01 00:00:00'SET @AGE = 0IF DATEADD(YEAR, DATEDIFF (YEAR, [JnrDOB], @TARGETDATE), [JnrDOB]) > @TARGETDATE BEGIN SET @AGE = DATEDIFF(YEAR, [JnrDOB], @TARGETDATE) - 1END IF DATEADD(YEAR, DATEDIFF (YEAR, [JnrDOB], @TARGETDATE), [JnrDOB]) < @TARGETDATE BEGIN SET @AGE = DATEDIFF(YEAR, [JnrDOB], @TARGETDATE)ENDNow having calculated the number of years in'@AGE' I want to write that into the appropriate table field.Please helpRichard |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
rhall47
Starting Member
2 Posts |
Posted - 2011-09-02 : 14:43:44
|
| Hi Tara,It's not so much the age, I do understand your point but the team which the player has been assigned too based on his age as at the 1st of SeptemberThis would then say his was assigned to the "Under 7's" or "Under 8's" etc |
 |
|
|
|
|
|
|
|