January 7, 2005 at 10:47 am
I am needing to select from ubirthdate from table1 all persons that are age 16 from a date range getdate() + 7. I'm stuck.....can anyone help. This is what I have and it DOES not work.
select ubirthdate
from contact2
where CAST(substring(ubirthdate,4,3) AS Varchar) = CAST(substring(getdate(),4,3) AS Varchar)
and CAST(substring(ubirthdate,1,2) AS Varchar) between
CAST(substring(getdate(),1,2) AS Varchar) and CAST((substring(getdate(),1,2) + 7) AS Varchar)
and (YEAR(getdate()) - YEAR(ubirthdate) = 16)
HELP
January 7, 2005 at 12:26 pm
Can you provide a schema and data example?
January 7, 2005 at 12:30 pm
Here is an example of the date in the contact2 table - column ubirthday
1986-12-08 00:00:00.000
1986-10-28 00:00:00.000
1986-03-31 00:00:00.000
1986-11-21 00:00:00.000
January 7, 2005 at 12:41 pm
You're trying to get the birthdates off all people who are 16 and who's birthdays are in the next week?
January 7, 2005 at 12:43 pm
Everyone who is 16 within the week
January 7, 2005 at 1:02 pm
Try this...
select ubirthdate from contact2
where dateadd(year, 16, ubirthdate)
between convert(varchar(12), getdate()) and convert(varchar(12), dateadd(day, 7, getdate()))
January 7, 2005 at 1:25 pm
Thank you, Thank you, Thank you
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply