May 22, 2012 at 12:47 pm
SQL Kiwi (5/22/2012)
chalbert's code
DATEDIFF(YY,dbo.b_ENROLLMENT.MEMBER_DOB_DATE,GETDATE()) as age
This doesn't compute someone's age. It needs a formula like:
Age =
CASE
WHEN DATEPART(DAY, dbo.b_ENROLLMENT.MEMBER_DOB_DATE) > DATEPART(DAY, GETDATE())
THEN DATEDIFF(MONTH, dbo.b_ENROLLMENT.MEMBER_DOB_DATE, GETDATE()) - 1
ELSE DATEDIFF(MONTH, dbo.b_ENROLLMENT.MEMBER_DOB_DATE, GETDATE())
END / 12
See http://www.sqlteam.com/article/datediff-function-demystified
Details details... I expected that to be the OPs next question/post 🙂
Jared
CE - Microsoft
May 22, 2012 at 12:56 pm
Sean Lange (5/22/2012)
I wasn't even going to mention that Paul, there look to be so many other possible issues with this.
You both make very reasonable points there :laugh:
May 23, 2012 at 12:27 pm
Doesn't that give you the age as of the day it is run?
May 23, 2012 at 12:29 pm
What is OP? Be kind guys
May 23, 2012 at 12:29 pm
chalbert (5/23/2012)
Doesn't that give you the age as of the day it is run?
No, try running the following:
SELECT DATEDIFF(YY,'20111231','20120101') as age
May 23, 2012 at 12:29 pm
chalbert (5/23/2012)
What is OP? Be kind guys
OP == Original Poster
May 23, 2012 at 12:30 pm
diva_di_dati (5/23/2012)
What is OP? Be kind guys
OP = Original Poster
--EDIT--
Now just stop Lynn...that is about the 10th post you did this today!!! 😛
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
May 23, 2012 at 12:32 pm
Did you read the article that Paul posted? It explains DATEDIFF quite well. Here is again so you don't have to scroll around for it.
http://www.sqlteam.com/article/datediff-function-demystified
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
May 23, 2012 at 12:37 pm
thx
Viewing 9 posts - 16 through 23 (of 23 total)
You must be logged in to reply to this topic. Login to reply