Solved

each month

Posted on 2008-06-13
2
189 Views
Last Modified: 2010-03-20
bit brain dead today, i have this code, how can i make it automatically do previous month at the mo i have to enter manually....


select count(*) as times,member_id,licensed,used 

from user_count 

where used > licensed+1 and dt_stamp between '2007-02-01' and '2007-02-28'

group by member_id,licensed,used

order by member_id, used

Open in new window

0
Comment
Question by:James Murrell
2 Comments
 
LVL 15

Accepted Solution

by:
Lee Osborne earned 500 total points
Comment Utility
You could use the WHERE like this:

WHERE used > licensed+1 and dt_stamp BETWEEN DateSerial(Year(Now()), Month(Now()) - 1, 1) AND DateSerial(Year(Now()), Month(Now()), 0)

This should look at the previous month.
0
 
LVL 60

Expert Comment

by:chapmandew
Comment Utility
select count(*) as times,member_id,licensed,used
from user_count
where used > licensed+1 and dt_stamp between dateadd(m, -1, getdate()) and gettdate()
group by member_id,licensed,used
order by member_id, used
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Via a live example, show how to shrink a transaction log file down to a reasonable size.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now