Separating working hours with non-working hours SQL Please can someone assist? I need to break up data between working hours and non-working hours (weekends also need to be taken into consideration).

I'm not really sure where to begin, other than:

select *
from Electricalconsumptionhalfhourview
where meterID = 17635382
  and [Date] &lt; '2015-02-28 23:59:59.000'
  and [Date] &gt; '2015-02-01 00:00:00.000'


Thanks for the help guys... I eventually settled on doing this... 

select *
into #WorkingHours
from Electricalconsumptionhalfhourview
where meterID = 17635382
  and [Date] &gt; '2015-02-01 00:00:00.000'
  and [Date] &lt; '2015-02-28 23:59:59.000'

select *
into #NonWorkingHours
from Powerstardatahalfhourcacheview
where meterID = 1458194
  and [Date] &gt; '2015-02-01 00:00:00.000'
  and [Date] &lt; '2015-02-28 23:59:59.000'

SELECT *
FROM #WorkingHours
WHERE DATEPART(hh, [Date]) &gt; 8 --Start of working hours
  AND DATEPART(hh, [Date]) &lt; 17 --End of working hours
  AND DATEPART(dd, [Date]) NOT in (1,7,8,14,15,21,22,28)
  AND DATEPART(mm, [Date]) = 2

SELECT * 
FROM #NonWorkingHours
WHERE DATEPART(hh, [Date]) &lt; 8  --Start of working ho
   OR DATEPART(hh, [Date]) &gt; 17  --End of working hours
  AND DATEPART(mm, [Date]) = 2
UNION
SELECT * FROM #NonWorkingHours
WHERE DATEPART(dd, [Date]) in (1,7,8,14,15,21,22,28)
  and DATEPART(mm, [Date]) = 2'
If I can understand what you are asking I wrote this code for you. This is when your workweek will be from monday till friday and your workhours will be from 8 to 17

select *
      from (
           select
           case when datename(dw,[date]) in ('Saturday','Sunday') then 'Weekend' else 'Week' end as WeekendOrWeek,
           datepart(HOUR,[date]) as HourDate,
           *
           from Electricalconsumptionhalfhourview
           where meterID = 17635382
           )WeekDays
where WeekDays.WeekendOrWeek = 'Week' and WeekDays.Hourdate &gt; 8 and WeekDays.HourDate &lt; 17


This is written for T-SQL. (SQL Server) If you want to get the dates which are not in the week just edit the where clause.