Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
drbarbu
Starting Member
4 Posts |
Posted - 2008-08-05 : 05:00:00
|
| Dear all,I want to select a specific period of date based on month and day. What I need something like:SELECT * FROM table WHERE bDate BETWEEN '7/24' AND '8/2'This query should display all the birthdays that are in this period.It's the first time when I have to do something like this and I'm stuck. I don't know how to do this.I hope you can help me.Thanks. |
|
|
harlingtonthewizard
Constraint Violating Yak Guru
352 Posts |
Posted - 2008-08-05 : 05:08:26
|
| This may give you some ideas. What does your table and fields look like?http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=107666 |
 |
|
|
drbarbu
Starting Member
4 Posts |
Posted - 2008-08-05 : 05:22:19
|
| The table looks like a normal one, with only one column that's storing the birth date for each client.The example you gave it doesn't help me at all.I need all the birthdays for the current week for - let's say - the last 70 years.Here is the table structure:[ code]CREATE TABLE [dbo].[Pacient]( [PacientID] [int] IDENTITY(1,1) NOT NULL, [PacientLName] [varchar](50) NULL, [PacientFName] [varchar](50) NULL, [PacientBirthDate] [datetime] NULL, [PacientRegDate] [datetime] NULL CONSTRAINT [DF_Pacient_PacientRegDate] DEFAULT (getdate()), CONSTRAINT [PK_Pacient] PRIMARY KEY CLUSTERED ( [PacientID] ASC)[ /code] |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-08-05 : 05:33:50
|
quote: Originally posted by drbarbu Dear all,I want to select a specific period of date based on month and day. What I need something like:SELECT * FROM table WHERE bDate BETWEEN '7/24' AND '8/2'This query should display all the birthdays that are in this period.It's the first time when I have to do something like this and I'm stuck. I don't know how to do this.I hope you can help me.Thanks.
What is the year value?MadhivananFailing to plan is Planning to fail |
 |
|
|
drbarbu
Starting Member
4 Posts |
Posted - 2008-08-05 : 05:36:41
|
| As I said, I'm not interested in the year because I need to know the birth dates for the current week for the last 70 years and not all the birthdays in the last 70 years. |
 |
|
|
drbarbu
Starting Member
4 Posts |
Posted - 2008-08-05 : 14:01:56
|
| The problem is solved. Here is the solution:WHERE DATEPART(week, PacientBirthDate) >= DATEPART(week, @WeekStart) AND DATEPART(week, PacientBirthDate) < DATEPART(week, @WeekStop) This is going to show all the birth dates from the current week.Hope it will help others. |
 |
|
|
|
|
|
|
|