MS SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMS SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 26th, 2004, 01:01 PM
reeljustice reeljustice is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2002
Posts: 13 reeljustice User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to reeljustice
DATEADD - Count events for LAST MONTH, Count events for NEXT MONTH

Okay, thanks to help and pulling out hair, I able to COUNT specific caterories of events for the CURRENT MONTH from my calendar. This is the SQL Query that is working:

SELECT COUNT(ItemID) AS [Total Closings for Current Month] FROM CalendarEvents inner join CalendarCategories
on CalendarEvents.CalCategoryID = CalendarCategories.CalCategoryID
WHERE CalendarEvents.CalCategoryID IN (1, 2, 3, 4, 20) AND month(StartDate)=month(getdate()) AND year(StartDate)=year(getdate()) AND CalendarEvents.ModuleID = 360


Now, I'm trying to COUNT the events with specific categories from the NEXT MONTH and from the PREVIOUS MONTH.

This is what I tried for events from LAST MONTH but it returns an incorrect quantity:
SELECT COUNT(ItemID) AS [Total Closings for LAST Month]
FROM
CalendarEvents
INNER JOIN
CalendarCategories
ON
CalendarEvents.CalCategoryID = CalendarCategories.CalCategoryID
WHERE
CalendarEvents.CalCategoryID IN (1, 2, 3, 4, 20)
AND
(StartDate <= DATEADD(MONTH, -1, (CONVERT(char(10), GETDATE(), 101)))
AND
StartDate > DATEADD(MONTH, -2, (CONVERT(char(10), GETDATE(), 101))))
AND
CalendarEvents.ModuleID = 360

This is the INCORRECT quantity for NEXT MONTH'S events:
SELECT COUNT(ItemID) AS [Total Closings for NEXT Month]
FROM
CalendarEvents
INNER JOIN
CalendarCategories
ON
CalendarEvents.CalCategoryID = CalendarCategories.CalCategoryID
WHERE
CalendarEvents.CalCategoryID IN (1, 2, 3, 4, 20)
AND
(StartDate >= DATEADD(MONTH, 1, (CONVERT(char(10), GETDATE(), 101)))
AND
StartDate < DATEADD(MONTH, 2, (CONVERT(char(10), GETDATE(), 101))))
AND
CalendarEvents.ModuleID = 360

HELP PLEASE

Reply With Quote
  #2  
Old March 1st, 2004, 05:07 PM
sypher sypher is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: Montreal
Posts: 92 sypher User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 m 10 sec
Reputation Power: 5
first of all your not doing the same query for the current month and the last/next month...try to put the month(...) and year(...) like the current query into your other query

P.s Next time try to think about writting one query or SP with different param, instead of writting 3(just a hint...I know that sometime you really got no choice.)

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > DATEADD - Count events for LAST MONTH, Count events for NEXT MONTH


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT