rstelma and arnabghosh, the DATEPART(dw, value) depends on the SET DATEFIRST setting in SQL Server.
If I run this code on my computer
Code:
SELECT value, DATEPART(dw, value) FROM fnSeqDates('7/1/2006', '7/31/2006')
I get this result
Code:
2006-07-01 00:00:00.000 7
2006-07-02 00:00:00.000 1
2006-07-03 00:00:00.000 2
2006-07-04 00:00:00.000 3
2006-07-05 00:00:00.000 4
2006-07-06 00:00:00.000 5
2006-07-07 00:00:00.000 6
2006-07-08 00:00:00.000 7
2006-07-09 00:00:00.000 1
2006-07-10 00:00:00.000 2
2006-07-11 00:00:00.000 3
2006-07-12 00:00:00.000 4
2006-07-13 00:00:00.000 5
2006-07-14 00:00:00.000 6
2006-07-15 00:00:00.000 7
2006-07-16 00:00:00.000 1
2006-07-17 00:00:00.000 2
2006-07-18 00:00:00.000 3
2006-07-19 00:00:00.000 4
2006-07-20 00:00:00.000 5
2006-07-21 00:00:00.000 6
2006-07-22 00:00:00.000 7
2006-07-23 00:00:00.000 1
2006-07-24 00:00:00.000 2
2006-07-25 00:00:00.000 3
2006-07-26 00:00:00.000 4
2006-07-27 00:00:00.000 5
2006-07-28 00:00:00.000 6
2006-07-29 00:00:00.000 7
2006-07-30 00:00:00.000 1
2006-07-31 00:00:00.000 2
So for me Saturday is 7 and Sunday is 1.
So if I write
Code:
SELECT count(*) FROM fnSeqDates('7/1/2006', '7/31/2006') where DATEPART(dw, value) in (1, 7)
I get 10 as the expected result.