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 September 19th, 2004, 01:56 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
List or Count bal of mth & mth todate

I need to count and to list events for the current month todate and to count and list event for the rest or balance of the month.

Could someone assist me in preparing these separate queries? Thank you in advance for your assistance.

Thisis my query for list all events for the current month:

SELECT EventTimeBegin AS [Closing Date - Time], EventName AS [File No], AttyLName AS [Atty], Borrower1LName AS [Borrower], Borrower1FName AS [First], ProcessorLName AS [Processor], LOLName AS [LO], ClosingLocation AS [Location], MtgeBroker AS [Broker], EventID AS [ID], ModuleID AS [MID], CreatedDate AS [Order Date]

FROM RECalendar

WHERE

(
RECalendar.FileType IN ('CONSTR','ConstrPerm','Constr Refi Table Fund','Conv Refi','FHA Refi','HELOC','Purchase 0 Loan','Purchase Loan','Purchase Cash','Witness')
AND
RECalendar.ModuleID IN ('581','582','583','584','585','586','587','588','589','590','591','592','593','594','595','596','59 7','603','733','747','750','751','752','753','754','755','756','757','758','759','761','762','763',' 764','765','766','767','768','769','771','772','773','774','775','776','777','778','779','780','781' ,'782','783','784','785','786','814','815','816','817','818','819','820','821','822','823','824','82 5','826','827','828','829','830','831','832','833','834','887','888','889','890','891','892','893',' 894','895','896','897','898','899','900','901','902','903','904','905','906','907','908','909','910' ,'911','912','914','915')
)

AND

(
month(EventTimeBegin)=month(getdate())
AND
year(EventTimeBegin)=year(getdate())
)

ORDER BY EventTimeBegin ASC

Reply With Quote
  #2  
Old September 19th, 2004, 02:17 PM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 17,921 r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level) 
Time spent in forums: 1 Month 4 Weeks 12 h 58 m 55 sec
Reputation Power: 1022
you cannot count and list at the same time
__________________
r937.com | rudy.ca

Reply With Quote
  #3  
Old September 19th, 2004, 09:14 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
Quote:
Originally Posted by r937
you cannot count and list at the same time


I understand that. My question was not clear.

I need to count the events from the 1st of the month to the current day in 1 query, then, in another query, list the events from the 1st day of the month until the current day.

In the other 2 queries, I need to count the events for the rest of the month in one query and list the events for the rest of the month in another query.

The following was provided in another forum. I am about to review the suggestion and test them.

if i get your question correctly:

events untill today:
...
AND
(month(EventTimeBegin)=month(getdate())
AND
year(EventTimeBegin)=year(getdate())
and
datediff(d, EventTimeBegin, getdate()) <= 0
)

and for the rest of the month:
...
AND
(month(EventTimeBegin)=month(getdate())
AND
year(EventTimeBegin)=year(getdate())
and
datediff(d, EventTimeBegin, getdate()) > 0
)

you can substitute
(month(EventTimeBegin)=month(getdate())
AND
year(EventTimeBegin)=year(getdate())
with
datediff(m, EventTimeBegin, getdate()) = 0

Reply With Quote
  #4  
Old September 19th, 2004, 09:39 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
Just tested the queries, they work great.

Reply With Quote
  #5  
Old September 19th, 2004, 09:46 PM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 17,921 r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level) 
Time spent in forums: 1 Month 4 Weeks 12 h 58 m 55 sec
Reputation Power: 1022
they work but will not scale well (any index on EventTimeBegin will be ignored because of the functions performed on it)

better for events until today --

where EventTimeBegin between F and getdate()

better for events after today --

where EventTimeBegin between getdate() and L

now, all you gotta do is come up with expressions for F (the first day of the current month) and L (the last day of the current month)

then both WHERE clauses will be efficient, and the index will be used

F would be dateadd(dd,-day(getdate())+1,getdate())

L would be dateadd(mm,1,dateadd(dd,-day(getdate()),getdate()))

Last edited by r937 : September 19th, 2004 at 09:50 PM.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > List or Count bal of mth & mth todate


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 4 hosted by Hostway
Stay green...Green IT