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

CountWeeksDays

$
0
0

Experts,

We have Date table with some sample recorde as :-

DECLARE	@param_StartDate	VARCHAR(10)
DECLARE	@param_EndDate		VARCHAR(10)

SET		@param_StartDate	= '2013-05-19'
SET		@param_EndDate		= '2013-05-26'

SELECT
	Dt,
	Day,
	IsWorkday,
	Year,
	WeekNumber
FROM
	Date
WHERE
	(
		CONVERT(VARCHAR(10), Dt, 112)
			BETWEEN CONVERT(VARCHAR(10), CAST(@param_StartDate AS DATE), 112)
			AND CONVERT(VARCHAR(10), DATEADD(DD, 6, CAST(@param_EndDate AS DATE)), 112)
	)

O/p of above query is something like this:-

Dt	Day	IsWorkday	Year	WeekNumber
20130519	Sunday	0	2013	21
20130520	Monday	1	2013	21
20130521	Tuesday	1	2013	21
20130522	Wednesday	1	2013	21
20130523	Thursday	1	2013	21
20130524	Friday	1	2013	21
20130525	Saturday	0	2013	22
20130526	Sunday	0	2013	22
20130527	Monday	0	2013	22
20130528	Tuesday	1	2013	22
20130529	Wednesday	1	2013	22
20130530	Thursday	1	2013	22
20130531	Friday	1	2013	22
20130601	Saturday	0	2013	23

Expected o/p as:-

StartDate	TotalWorkingDaysInWeek
2013-05-19	5
2013-05-26	4

Help please?

Thanks

Kumar


Please do let us know your feedback. Thank You - KG, MCTS


Viewing all articles
Browse latest Browse all 23857

Trending Articles



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