?
Solved

Need Query to select birthday  in dttime format

Posted on 2003-02-28
6
Medium Priority
?
431 Views
Last Modified: 2012-06-27
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?

0
Comment
Question by:IT Gal
[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
  • 2
  • 2
6 Comments
 

Expert Comment

by:ramaswamy_ravi
ID: 8045101
select MONTH(DOB) = MONTH(GETDATE() AND DAY(DOB) = DAY(GETDATE()) FROM Table1

Ravi
0
 

Author Comment

by:IT Gal
ID: 8057711
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.
0
 

Expert Comment

by:ramaswamy_ravi
ID: 8058966
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
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:IT Gal
ID: 8059407
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!
0
 

Expert Comment

by:modulo
ID: 8263622
Dear expert(s),

A request has been made to close this Q in CS:
http://www.experts-exchange.com/Community_Support/Q_20573332.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
0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 8278639
Saving this Q as a PAQ and refunding the 50 points to the questionner

modulo

Community Support Moderator
Experts Exchange
0

Featured Post

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

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

When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

770 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