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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 SQLQuery Return UPComing Birthday List Next 2 Days

Author  Topic 

pankaj.pareek@sparrowi.co
Starting Member

26 Posts

Posted - 2008-09-01 : 01:56:15
Dear All,

I need a SQL Query Return UPComing Birthday List within Next 2 Days.

MY Query Given Below :


"Select E_code,FirstName,MiddleName,LastName,DOB,AnniversaryDate,Designation,Department,BusinessEmail,day(DOB)as uday,datename(month,DOB)as umonth,year(getdate()) as cyear from tbl_Emp_Core where ( (day(DOB) = day(getdate()+1)) OR (day(DOB) = day(getdate()+2)) ) and ( Month(DOB) = Month(getdate()) )"




Regards
Rishi Sharma

sunil
Constraint Violating Yak Guru

282 Posts

Posted - 2008-09-01 : 02:18:12
Declare @Table table
( birthdate datetime
)
Insert @Table

Select getdate()+1 UNION ALL
Select getdate()+2 UNION ALL
Select getdate()+3

select * from @Table
where
datediff(Year, birthdate, getdate()) - case when dateadd(year,datediff(Year, birthdate, getdate()),birthdate) > getdate() then 1 else 0 end
<
datediff(Year, birthdate, dateadd(dd,2,getdate())) - case when dateadd(year,datediff(Year, birthdate, dateadd(dd,2,getdate())),birthdate) > dateadd(dd,2,getdate()) then 1 else 0 end

You can take help from where clause.
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-09-01 : 02:25:54
[code]DECLARE @sample TABLE
(
dob datetime
)

INSERT INTO @sample (dob)
SELECT '19000831' UNION ALL
SELECT '19000901' UNION ALL
SELECT '19000902' UNION ALL
SELECT '19000903' UNION ALL
SELECT '19000904'

SELECT *
FROM
(
SELECT *,
bd_this_year = DATEADD(YEAR, DATEPART(YEAR, GETDATE()) - DATEPART(YEAR, dob), dob)
FROM @sample s
) d
WHERE d.bd_this_year > DATEADD(DAY, DATEDIFF(DAY, 0, GETDATE()), 0)
AND d.bd_this_year <= DATEADD(DAY, DATEDIFF(DAY, 0, GETDATE()), 2)[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

sajinair76
Starting Member

1 Post

Posted - 2011-02-14 : 00:53:36
You can use the below simple query to generate next 2 days birth day


select date_of_birth, * from mt_employee_general_master
where month(date_of_birth) = month(getdate())
and day(date_of_birth) in ( day(getdate()) + 1 , day(getdate()) + 2)

Saji Nair
Go to Top of Page
   

- Advertisement -