Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase ««12

Birthdays in next 7 days Expand / Collapse
Author
Message
Posted Tuesday, January 1, 2013 5:27 AM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Yesterday @ 7:09 PM
Points: 23,218, Visits: 31,905
opc.three (1/1/2013)
Note: thread is 2+ years old


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.



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)
Post #1401582
Posted Tuesday, January 1, 2013 5:36 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 9:38 PM
Points: 7,097, Visits: 12,598
Lynn Pettis (1/1/2013)
opc.three (1/1/2013)
Note: thread is 2+ years old


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
Post #1401584
Posted Friday, December 27, 2013 10:02 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, August 13, 2014 8:34 AM
Points: 7, Visits: 249
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

Post #1526216
« Prev Topic | Next Topic »

Add to briefcase ««12

Permissions Expand / Collapse