troubleshooting Question

Help with SQL 2008 Stored Procedure

Avatar of mburk1968
mburk1968Flag for United States of America asked on
Microsoft SQL Server 2008
4 Comments1 Solution308 ViewsLast Modified:
I have the following subquery that calculates the variance in PTO that you have accrued versus the amount that has been approved. Currently if you haven't taken any PTO the varience displays a 0. What I want to display is if the varience = 0 then DATEPART(M, GETDATE( )) * ( PL.Accrual ) = Variance


,ISNULL(( SELECT DATEPART(M, GETDATE( )) * ( PL.Accrual )
                                - SUM(TotalHoursUsed)
                         FROM   PTORequest PR
                                LEFT OUTER JOIN PTOBeginningBalances PB ON PR.EmployeeUsername = PB.EmployeeUsername
                                LEFT OUTER JOIN PTOLevelsAccrualHours PL ON PB.Level = PL.Level
                         WHERE  PBAL.EmployeeUsername = PR.EmployeeUsername
                                AND NOT SUBSTRING(PTOType, 4, LEN(PTOType) - 3) = 'Carryover'
                                AND ( YEAR(PB.Year) = YEAR(GETDATE()) )
                                AND SUBSTRING(PR.Status, 4, LEN(PR.Status) - 3) = 'Approved'
                                AND StartDateAndTime > DATEADD(yy,
                                                           DATEDIFF(yy, 0,
                                                              GETDATE()), 0)
                                                AND StartDateAndTime < DATEADD(m,
                                                           DATEDIFF(m, -1,
                                                              GETDATE()), 0)
                         GROUP BY PL.Accrual
                       ), 0) AS [Variance]
ASKER CERTIFIED SOLUTION
mburk1968

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros