| 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()) )"RegardsRishi Sharma |
|
|
sunil
Constraint Violating Yak Guru
282 Posts |
Posted - 2008-09-01 : 02:18:12
|
| Declare @Table table( birthdate datetime)Insert @TableSelect getdate()+1 UNION ALLSelect getdate()+2 UNION ALLSelect getdate()+3 select * from @Tablewheredatediff(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 endYou can take help from where clause. |
 |
|
|
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 ALLSELECT '19000901' UNION ALLSELECT '19000902' UNION ALLSELECT '19000903' UNION ALLSELECT '19000904'SELECT *FROM( SELECT *, bd_this_year = DATEADD(YEAR, DATEPART(YEAR, GETDATE()) - DATEPART(YEAR, dob), dob) FROM @sample s) dWHERE 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] |
 |
|
|
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 dayselect date_of_birth, * from mt_employee_general_masterwhere month(date_of_birth) = month(getdate())and day(date_of_birth) in ( day(getdate()) + 1 , day(getdate()) + 2)Saji Nair |
 |
|
|
|
|
|