Solved

SQL Query question

Posted on 2013-01-17
2
269 Views
Last Modified: 2013-01-17
Good day. I am trying to use the following to find the Age as of a specific date (11/1/12). It doesn't seem to work for all. On some, the age does match what it should be but on some it adds an extra year.

DOB field contains dates as "1997-06-06 00:00:00.000"

The query is CAST(Round((DateDiff(d,id.DOB,'2012-11-01')/365.25),0)  as INT) as AGE

For instance, I have one record where the DOB field is "1995-05-01 00:00:00.000" and the Age comes out as 18 but should be 17.

Any idea how I can get it so that it provides the proper age as of the date requested?
0
Comment
Question by:mig1980
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 39

Accepted Solution

by:
appari earned 250 total points
ID: 38789981
that was because of round function you used.
use floor function as follows
CAST(floor((DateDiff(d,id.DOB,'2012-11-01')/365.25))  as INT) as AGE
0
 

Author Comment

by:mig1980
ID: 38790039
Perfect. Thank you very much!!
0

Featured Post

Free eBook: Backup on AWS

Everything you need to know about backup and disaster recovery with AWS, for FREE!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question