Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
SQL Server 2008
»
T-SQL (SS2K8)
»
Age
15 posts, Page 2 of 2
««
1
2
Age
Rate Topic
Display Mode
Topic Options
Author
Message
Jeff Moden
Jeff Moden
Posted Tuesday, September 25, 2012 1:43 PM
SSC-Dedicated
Group: General Forum Members
Last Login: Today @ 1:51 PM
Points: 32,906,
Visits: 26,789
Michael Valentine Jones (9/25/2012)
You can use the function on the link below to find the age:
Age Function F_AGE_IN_YEARS
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=74462
Any chance of making it NOT a scalar function?
--Jeff Moden
"
RBAR
is pronounced "ree-bar" and is a "Modenism" for "
R
ow-
B
y-
A
gonizing-
R
ow".
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."
For better, quicker answers on T-SQL questions, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
Post #1364270
Paul White
Paul White
Posted Tuesday, September 25, 2012 2:42 PM
SSChampion
Group: General Forum Members
Last Login: Today @ 7:18 PM
Points: 10,989,
Visits: 10,532
Jeff Moden (9/25/2012)
Careful now... Because of the date conversions to the CHAR datatype, that will be relatively slow.
It is beautiful though - this has long been a favourite of mine (I think it was Rob Farley that first showed it to me).
As far as performance is concerned, well yes it will be slow. But then, all
T-SQL
solutions will be slow, right?
Just kidding (mostly) - it's a good point that conversion to string is particularly bad. And especially scalar T-SQL UDFs
Paul White
SQL Server MVP
SQLblog.com
@SQL_Kiwi
Post #1364289
Michael Valentine Jones
Michael Valentine Jones
Posted Tuesday, September 25, 2012 3:18 PM
SSCrazy
Group: General Forum Members
Last Login: Today @ 3:28 PM
Points: 2,944,
Visits: 10,502
Jeff Moden (9/25/2012)
Michael Valentine Jones (9/25/2012)
You can use the function on the link below to find the age:
Age Function F_AGE_IN_YEARS
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=74462
Any chance of making it NOT a scalar function?
I originally wrote this for SQL 2000, so be my guest.
The code could be greatly simplified too, probably enough to convert it to inline code.
I posted it mainly to give them an example of some code that I know I tested fairly completely.
Post #1364310
Sergiy
Sergiy
Posted Sunday, February 17, 2013 6:59 PM
SSCarpal Tunnel
Group: General Forum Members
Last Login: Wednesday, May 15, 2013 5:01 PM
Points: 4,540,
Visits: 8,184
Jeff Moden (9/25/2012)
Michael Valentine Jones (9/25/2012)
You can use the function on the link below to find the age:
Age Function F_AGE_IN_YEARS
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=74462
Any chance of making it NOT a scalar function?
SELECT DATEDIFF(yy, 0, GETDATE() - DOB) Age_Way1,
YEAR(GETDATE()-DOB) -1900 Age_Way2
Post #1421022
jshahan
jshahan
Posted Tuesday, February 19, 2013 3:44 PM
SSC-Enthusiastic
Group: General Forum Members
Last Login: Today @ 4:41 PM
Points: 135,
Visits: 719
My two bits...
declare @dob datetime
set @dob = '2/29/2000'
select convert(char(10),@dob,101) as DOB,
case
when ((MONTH(@dob) * 100) + DAY(@dob)) > ((MONTH(getdate()) * 100) + DAY(getdate()))
then DATEDIFF(year,@dob,getdate()) - 1
else DATEDIFF(year,@dob,getdate()) End as AgeInYears
Post #1421879
« Prev Topic
|
Next Topic »
15 posts, Page 2 of 2
««
1
2
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.