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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Doubt regarding a query

Author  Topic 

chandusama
Starting Member

13 Posts

Posted - 2008-01-21 : 21:02:25
hi guyz...this is my first doubt here as i have taken up an sql server course this semester
i am finding it tuff with one particular query...can sum one help me with this

18. Generate a recordset of all people whose birthday falls within +/- two weeks from whenever the query is run.


Sama

singularity
Posting Yak Master

153 Posts

Posted - 2008-01-21 : 21:29:38
Use the datediff function.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-01-22 : 00:41:56
where birthday>=dateadd(week,-2,dateadd(day,datediff(day,0,getdate()),0)) and birthday<=dateadd(week,2,dateadd(day,datediff(day,0,getdate()),0))

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

chandusama
Starting Member

13 Posts

Posted - 2008-01-22 : 01:46:44
quote:
Originally posted by madhivanan

where birthday>=dateadd(week,-2,dateadd(day,datediff(day,0,getdate()),0)) and birthday<=dateadd(week,2,dateadd(day,datediff(day,0,getdate()),0))

Madhivanan

Failing to plan is Planning to fail





thanks verymuch madhivanan....the query worked...
thanks again

Sama
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-01-22 : 02:19:19
All future birthdays, or only the day they were born?
If you want only the day they were born, use the query above.
If you want their birthdays, see http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=80709


E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page
   

- Advertisement -