IT Gal
asked on
Need Query to select birthday in dttime format
Hello All,
Im very much a newbie, so forgive me if this sounds dumb, but I have a problem with what seems like it should be a simple query.
I have MS SQL 7 running, and I have a table with a dttime value column named 'DOB' with birthdays in it. I want to write a script that querys the database daily to create a recordset of users in that database who have a birthday equal to the current date. To do this, I would need to wildcard a date query so it only looks for the month and date, but not year.
I know I can use a LIKE statement to find everyone with a birthday in a specific MONTH, but how can I combine the date with that also? Can anyone help me?
Im very much a newbie, so forgive me if this sounds dumb, but I have a problem with what seems like it should be a simple query.
I have MS SQL 7 running, and I have a table with a dttime value column named 'DOB' with birthdays in it. I want to write a script that querys the database daily to create a recordset of users in that database who have a birthday equal to the current date. To do this, I would need to wildcard a date query so it only looks for the month and date, but not year.
I know I can use a LIKE statement to find everyone with a birthday in a specific MONTH, but how can I combine the date with that also? Can anyone help me?
ASKER
I couldnt get this statement to work, but I did finally get this one to do what I wanted it to:
SELECT * FROM MEMBERS WHERE DATEPART(MONTH,DOB) = 1 AND DATEPART(DAY,DOB) = 1
Which I guess is more or less the same thing.
Now does anyone know how I can make that execute in a vbscript so that the month and day values are automatically filled in with the current month value and the current date value so it can be passed to the SQL database to return a recordset? Just curious.
SELECT * FROM MEMBERS WHERE DATEPART(MONTH,DOB) = 1 AND DATEPART(DAY,DOB) = 1
Which I guess is more or less the same thing.
Now does anyone know how I can make that execute in a vbscript so that the month and day values are automatically filled in with the current month value and the current date value so it can be passed to the SQL database to return a recordset? Just curious.
I think there is asyntax error in the SQL
select MONTH(DOB) = MONTH(GETDATE()) AND DAY(DOB) = DAY(GETDATE()) FROM Table1
Try this. In any case, from VB Script u need to set up a connection and create a record set
In an earlier question, I have given the sample code.
Ravi
select MONTH(DOB) = MONTH(GETDATE()) AND DAY(DOB) = DAY(GETDATE()) FROM Table1
Try this. In any case, from VB Script u need to set up a connection and create a record set
In an earlier question, I have given the sample code.
Ravi
ASKER
This is how I ended up doing it and it seems to work well.
SELECT * FROM MEMBERS WHERE DATEPART(MONTH, DOB) = DATEPART(month, GETDATE()) AND DATEPART(DAY, DOB) = DATEPART(day, GETDATE())
Thanks for your help!
SELECT * FROM MEMBERS WHERE DATEPART(MONTH, DOB) = DATEPART(month, GETDATE()) AND DATEPART(DAY, DOB) = DATEPART(day, GETDATE())
Thanks for your help!
Dear expert(s),
A request has been made to close this Q in CS:
https://www.experts-exchange.com/questions/20573332/Would-like-points-refund-on-following-two-questions.html
Without a response in 72 hrs, a moderator will finalize this question by:
- Saving this Q as a PAQ and refunding the points to the questionner
When you agree or disagree, please add a comment here.
Thank you.
modulo
Community Support Moderator
Experts Exchange
A request has been made to close this Q in CS:
https://www.experts-exchange.com/questions/20573332/Would-like-points-refund-on-following-two-questions.html
Without a response in 72 hrs, a moderator will finalize this question by:
- Saving this Q as a PAQ and refunding the points to the questionner
When you agree or disagree, please add a comment here.
Thank you.
modulo
Community Support Moderator
Experts Exchange
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Ravi