Quantcast
Channel: Microsoft SQL Server
Viewing all articles
Browse latest Browse all 4871

TSQL - Filter a Group of Rows based on one Column's Value

$
0
0

I am trying to make a SQL query in Server 2008 R2 that selects the rows only for employees who have over 40 hours in a pay week and a pay description that doesn't include "over time". So far I have the following:

SQL
WITHRESULTSAS(SELECT[FullName],[PayHours],[SSN],[EffectiveDate],[PayDescription],[OrderNumber],[WeekStart],[WeekEnd],SUM(PayHours)OVER(PartitionBYFullName,WeekStart)ASTotalHoursFROM[viewReportPotentialOverTime]WHEREEffectiveDateBETWEEN'01/01/2015 00:00:00'AND'10/16/2015 23:59:59'GroupByFullName,SSN,WeekStart,WeekEnd,EffectiveDate,OrderNumber,PayDescription,PayHours)SELECT*FROMRESULTSWHERETotalHours40--AND PayDescription !='Overtime Pay'OrderByFullName,WeekStart,EffectiveDate
This gets me close to what I need. The problem I'm having is filtering out the rows for employees that do...

Viewing all articles
Browse latest Browse all 4871

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>