Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

query help

$
0
0

helle Experts..

I have below table.My requirement is to get Number of Saturdays and Sundays which have values '0' within a given date range.

Ex: Startdate= '2014-01-01 00:00:00:000',enddate = '2014-01-20 23:59:59.000'

OUTPUT Should be Count of saturdays+sundays which have value 0 for Date range in table which is""6" 

BUT for the daterange

Ex: Startdate= '2014-01-01 00:00:00:000',enddate = '2014-01-31 23:59:59.000' 

OUTPUT SHOULD BE "7" not "8" because in the table if you see after 2014-01-21 Sunday has "1".

Declare @Table Table (Sunday tinyint,Saturday tinyint,EffectiveFrom datetime,EffectiveTo datetime)
INSERT INTO @Table
SELECT 0,0,'2012-01-01 00:00:00.000','2012-12-31 23:59:59.000'
UNION 
SELECT 0,0,'2014-01-01 00:00:00.000','2014-01-20 23:59:59.000'
UNION 
SELECT 1,0,'2014-01-21 00:00:00.000','2014-12-31 23:59:59.000'
UNION 
SELECT 0,0,'2013-01-01 00:00:00.000','2013-12-31 23:59:59.000'
SELECT * from @Table


Viewing all articles
Browse latest Browse all 23857

Trending Articles



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