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 |
|
frankDK
Starting Member
14 Posts |
Posted - 2008-09-19 : 05:38:49
|
| HiCan anyone help on this one, in a sql2005 server, i need a total number of months since date of birth My table contains the following:id nr1 18090612342 18090543213 1809044444The first 6 numbers indicates date of birth:180906 = 18 sep 2006 - has been living for 24 months180905 = 18 sep 2005 - has been living for 36 months180904 = 18 sep 2004 - has been living for 48 monthsWhat i would like to have is a store procedure i could call with id as parameter.Hope you can help?Frank |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2008-09-19 : 05:46:04
|
What is the data type of nr ? convert it to datetime and then use datediff(month, dob, getdate()) find it KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
frankDK
Starting Member
14 Posts |
Posted - 2008-09-19 : 05:49:27
|
| It's nvarchar(10) |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2008-09-19 : 05:51:55
|
[code]select datediff(month, convert(datetime, '20' + substring(nr, 5, 2) + substring(nr, 3, 2) + left(nr, 2)), getdate())from yourtable[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
frankDK
Starting Member
14 Posts |
Posted - 2008-09-19 : 05:56:23
|
| Thank youit's working perfectlyfrank |
 |
|
|
|
|
|
|
|