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 |
|
omega1983
Starting Member
40 Posts |
Posted - 2009-12-08 : 16:51:25
|
| Here is a tablevar declareddeclare @Birthday1 table(birthmonth char(2),birthday char(2),birthyear char(4),ID char(10),birthday dateime)insert into @Birthday1 (birthmonth,birthday,birthyear,ID,birthday)select birthmonth,birthday,birthyear,ID,birthdayfrom birth_tableSample outputbirthmonth birthday birthyear ID birthday03 03 1939 2 1939-01-01 00:00:0004 04 1940 3 nullobjective#1Notivce that in the case of ID#2 their birthday is a null.I am trying to populate the birthday field with the birthmonth,birthday and birthyear from the three separate fields, which are text. This will enable me to use the birthday field in calculating the ageobjective#2How would I now use the populated birthday field to determine the age of the person |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2009-12-08 : 18:37:13
|
| I don't see how 03,03,1939 becomes '1939-01-01 00:00:00', but once you have your b'day as a date, use DATEDIFFOBJECTIVE 1UPDATE tableSET birthday = birthyear+birthmonth+birthday (you have two birthday fields, change one of the names).Objective 2SELECT datediff(day,birthday,getdate())/365 will give you the age in years for the person.JimN.B select datediff(year,'12/31/2009','01/01/2010) will give you 1 year. That's why it's better to days and divide by 365Everyday I learn something that somebody else already knew |
 |
|
|
|
|
|
|
|