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 |
|
steelkilt
Constraint Violating Yak Guru
255 Posts |
Posted - 2003-08-05 : 16:32:44
|
| Hi, I'm using DATEDIFF as below to get Age at time of Death for my DB. Anyone know how I could modify code below to give me a decimal version of the age, i.e. if someone is 37 1/2 could I get it to return 37.5?thx...ADD AgeDeath AS DATEDIFF(year, DEMOGRAPHICS.DOB, DEMOGRAPHICS.DOD) |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2003-08-05 : 16:36:51
|
| SELECT DATEDIFF(day, DEMOGRAPHICS.DOB, DEMOGRAPHICS.DOD)/CONVERT(float, 365)Tara |
 |
|
|
steelkilt
Constraint Violating Yak Guru
255 Posts |
Posted - 2003-08-05 : 16:58:43
|
| hey, thanks for the tip. I modified your code a bit to use DECIMAL data type so I could set precision and scale to lock in only five decimal places total (left and right), two of those decimal places to the right.thx again. |
 |
|
|
steelkilt
Constraint Violating Yak Guru
255 Posts |
Posted - 2003-08-05 : 17:22:32
|
| OK so now I see that SQL server is ignoring my wish to target precision and scale as below:ADD AgeDeath AS DATEDIFF(day, DEMOGRAPHICS.DOB, DEMOGRAPHICS.DOD)/CONVERT(decimal(5, 2), 365)QA isn't balking at the syntax, but the precision and scale settings I call for above don't make it to the actual table -- I get the default decimal settings.thx |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2003-08-05 : 17:27:36
|
| SELECT CONVERT(DECIMAL(5, 2), DATEDIFF(day, DEMOGRAPHICS.DOB, DEMOGRAPHICS.DOD)/CONVERT(DECIMAL(5, 2), 365))Tara |
 |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2003-08-06 : 08:51:30
|
Or go look at my bio...though I'm not dead yet...only feel that way..damn hangover.... Brett8-)SELECT POST=NewId() |
 |
|
|
|
|
|
|
|