June 12, 2009 at 9:52 am
Hi Everyone,
I am new to SQL Server 2000, Please somebody let me know how to "count the occurences of weekdays in a year" or else please provide me the code.
Please help me out.
Thanks in advance!!
June 12, 2009 at 10:19 am
kam7395 (6/12/2009)
Hi Everyone,I am new to SQL Server 2000, Please somebody let me know how to "count the occurences of weekdays in a year" or else please provide me the code.
Please help me out.
Thanks in advance!!
Here I build this for you, hope that helps!
/*SELECT top 1000000 identity(INT,1,1) AS N
INTO dbo.Tally
FROM master.sys.syscolumns sc1
CROSS JOIN master.sys.syscolumns sc2
CREATE UNIQUE CLUSTERED INDEX Clus_Tally_N ON dbo.Tally
(
N
) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO*/
DECLARE @inputDate1 DATETIME,
@InputDate2 DATETIME
SET @InputDate1 = '2009/06/11'
SET @InputDate2 = '2009/06/16'
SELECT datediff(d,@inputDate1,@InputDate2);
WITH Days(N)
AS (SELECT TOP 1000 N
FROM dbo.Tally),
Dates
AS (SELECT dateadd(d,N
- 1,@InputDate1) AS DATE,
datepart(dw,dateadd(d,N
- 1,@InputDate1)) AS DayOfWeek
FROM Days
WHERE N
- 1 <= datediff(d,@inputDate1,@InputDate2))
SELECT sum(CASE
WHEN DayOfWeek BETWEEN 2 AND 6
THEN 1
END) AS TotalDaysInWeek
FROM Dates
Cheers,
J-F
June 12, 2009 at 10:20 am
Oh Geez... SQL 2000, Sorry, my solution will not work, it's for 2005.
Sorry about that... I should've read the entire post..
Cheers,
J-F
June 12, 2009 at 10:24 am
Please don't cross post!
for reference see http://www.sqlservercentral.com/Forums/FindPost733984.aspx
June 12, 2009 at 3:18 pm
Thank You!
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply