Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Birthdays in next 7 days


Birthdays in next 7 days

Author
Message
Lynn Pettis
Lynn Pettis
SSC-Insane
SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)

Group: General Forum Members
Points: 24185 Visits: 37954
opc.three (1/1/2013)
Note: thread is 2+ years old Exclamation


Was noted, just responding to the alternate way the most recent responder posted. Plus, that is the beauty of this site, it doesn't matter how old a thread is, it still can help someone, and alternatives can still be found to solve the problem.

Cool
Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
Orlando Colamatteo
Orlando Colamatteo
SSCrazy Eights
SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)

Group: General Forum Members
Points: 8239 Visits: 14368
Lynn Pettis (1/1/2013)
opc.three (1/1/2013)
Note: thread is 2+ years old Exclamation


Was noted, just responding to the alternate way the most recent responder posted. Plus, that is the beauty of this site, it doesn't matter how old a thread is, it still can help someone, and alternatives can still be found to solve the problem.

Indeed. One of the many great qualities of this site. And in this case how appropriate is it that a thread that requires a solution that must deal with a date range that crosses a calendar-year-boundary would be resurrected on New Years Eve :-)

__________________________________________________________________________________________________
There are no special teachers of virtue, because virtue is taught by the whole community. --Plato
ken.hopkins
ken.hopkins
Forum Newbie
Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)

Group: General Forum Members
Points: 7 Visits: 255
Mad props to VINAY M JADIA for the change year function a few replies up. I was having difficulty getting the Day of the Week Name from a birthday in the future. With his ufnChangeYear function, my problem was solved. Granted there are multiple ways to skin this cat, but his approach worked for me. Here's my final compiled code from a few pilfered snippets (Credit and many thanks to the original coders).

Report consumed in a Microsoft Dynamics AX 4.0 SQL2005 Environment so you may need to tweak your Select Statement to make it suitable for your environment.


-- KH 12/27/2013 QUERY FOR SSRS HR BIRTHDAY REPORT

-- *********************************************************************
-- DECLARE AND SET VARIABLES BASED ON DBO.UFNCHANGEYEAR BY VINAY M JADIA.
-- *********************************************************************
DECLARE @DAYS INT
SET @DAYS = 365
DECLARE @DTF DATETIME, @DTT DATETIME
SET @DTF = CONVERT(DATETIME, CONVERT(VARCHAR(10), GETDATE(), 111))
SET @DTT = DATEADD(D, @DAYS, @DTF)

-- ESTABLISHES # OF DAYS TO LOOK IN FUTURE FOR EMPLOYEES WITH A BIRTHDAY

-- YOU WILL NEED TO COMMENT OUT "DECLARE @DAYS1" IN SSRS QUERY
DECLARE @DAYS1 DATETIME
-- COMMENT OUT "SET @DAYS1" IN SSRS AND ALLOW USER SPECIFIED INPUT
SET @DAYS1 = 30


-- GET COLUMN NAMES FOR REPORT
SELECT A.EMPLID ,A.FIRSTNAME ,A.LASTNAME ,A.BIRTHDATE ,A.HRMABSENCESETUPID AS [DEPT.] ,A.TITLE
,DBO.UFNCHANGEYEAR(A.BIRTHDATE,GETDATE()) AS [BIRTHDAY_THIS_YEAR]
,CONVERT(VARCHAR(8), A.BIRTHDATE, 1) AS [BIRTH_MM/DD/YY]
,CONVERT(CHAR(12),DATENAME(MONTH, A.BIRTHDATE)) AS [BIRTH_MONTH]
,CONVERT(CHAR(2),DATENAME(DAY, A.BIRTHDATE)) AS [BIRTH_DAY]
,CONVERT(CHAR(4),DATENAME(YEAR, A.BIRTHDATE)) AS [BIRTH_YEAR]
,DATEDIFF(DAY, GETDATE(), DATEADD(YEAR, DATEDIFF(YEAR, A.BIRTHDATE, GETDATE())
,A.BIRTHDATE)) + ABS(SIGN(DATEDIFF(DAY, GETDATE(), DATEADD(YEAR, DATEDIFF(YEAR, A.BIRTHDATE,
GETDATE()), A.BIRTHDATE))) - 1) / 2 * 365 AS [DAYS_UNTIL_BIRTHDAY]
,DATENAME(DW,(DBO.UFNCHANGEYEAR(A.BIRTHDATE,GETDATE()))) AS [BIRTHDAY_CURRENT_YEAR]
,FLOOR(DATEDIFF(DD,A.BIRTHDATE,GETDATE()) / 365.25) AS [AGE_NOW]

-- SSRS Query will need the following cast as Int statement substituted.
-- ,FLOOR(DATEDIFF(dd,A.BIRTHDATE,GETDATE()+ cast((@DAYS1) as int) ) / 365.25) AS [AGE_ON_BIRTHDAY]
,FLOOR(DATEDIFF(DD,A.BIRTHDATE,GETDATE()+(@DAYS1)) / 365.25) AS [AGE_ON_BIRTHDAY]

FROM EMPLTABLE AS A

WHERE A.STATUS IN (0,1) --PULLS EMPLOYED OR NONE STATUS EMPLOYEES

-- ****************************************************************
-- RESTRICTS DATA FEED TO EMPLOYEES WITH A BIRTHDAY IN NEXT ? DAYS.
-- ****************************************************************
-- SSRS Query will need the following cast as Int statement substitued.
-- AND 1 = (FLOOR(DATEDIFF(dd,A.BIRTHDATE,GETDATE()+ cast((@DAYS1) as int)) / 365.25))

AND 1 = (FLOOR(DATEDIFF(DD,A.BIRTHDATE,GETDATE()+ (@DAYS1)) / 365.25))
-
(FLOOR(DATEDIFF(DD,A.BIRTHDATE,GETDATE()) / 365.25))

ORDER BY DATEDIFF(DAY, GETDATE(), DATEADD(YEAR, DATEDIFF(YEAR, A.BIRTHDATE, GETDATE()), A.BIRTHDATE))
+ ABS(SIGN(DATEDIFF(DAY, GETDATE(),
DATEADD(YEAR, DATEDIFF(YEAR, A.BIRTHDATE, GETDATE()), A.BIRTHDATE))) - 1) / 2 * 365


Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search