473,408 Members | 2,832 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

SQL Report/View

We have a bookings table that records various information and for each
booking we record various events that users have performed on that booking
along with when the event occurred.

For example:-

Bookings EventLog
--------- ---------
BookID PK EvID Primary Key
BookDate BookID Foreign Key
BookStart Event
BookFinish, UserID
BookStatus,... EventTime

BookID 1 could have a date of 10/03/05, start time 09:00 and finish time
17:00.
A record gets created in the event table corresponding to which user created
the booking and at what time.
e.g. EvID = 1, BookID = 1, Event = 'Booking Created', UserID = 'dan',
EventTime = '2005/03/09 10:00'

Events get recorded to the EventLog table whenever something happens to the
booking (i.e. the booking status changes, date changes, etc).

We'd like to create a report that calculates the activity of all of our
users. Currently, we loop through all our users and perform individual SQL
queries that count the number of occurrences for a particular event in
between two dates specified.

e.g. SELECT count(EvID) FROM EventLog WHERE UserID = 'dan' AND Event =
'Booking Created' AND EventTime > '2005/03/01' AND EventTime < '2005/03/10'

This is obviously taking a lot of processing power and resources to
calculate and it slows our application down considerably whenever someone
attempts to view it.

Can anyone recommend a decent way to do this? Ideally, when someone wishes
to view this report (via ASP by the way), rather than it having to
recalculate the information using the datefrom and dateto dates they
specify, it should just displayed the information from a pre-calculated
view? In other words, is it possible to generate the reports overnight or
constantly in real-time, given that people will wish to view different
information at different times (i.e. different users and dates?)

Many thanks for any suggestions you can give me.

Dan Williams.
Jul 23 '05 #1
2 1425
Dan Williams (dt********@hotmail.com) writes:
We'd like to create a report that calculates the activity of all of our
users. Currently, we loop through all our users and perform individual SQL
queries that count the number of occurrences for a particular event in
between two dates specified.

e.g. SELECT count(EvID) FROM EventLog WHERE UserID = 'dan' AND Event =
'Booking Created' AND EventTime > '2005/03/01' AND EventTime <
'2005/03/10'
So what's wrong with

SELECT UserID, Count(EvID)
FROM eventlog
WHERE Event = 'Booking Created'
AND EventTime > '20050301' AND
AND EventTime < '20050310'
GROUP BY UsedID

?
Can anyone recommend a decent way to do this? Ideally, when someone wishes
to view this report (via ASP by the way), rather than it having to
recalculate the information using the datefrom and dateto dates they
specify, it should just displayed the information from a pre-calculated
view? In other words, is it possible to generate the reports overnight or
constantly in real-time, given that people will wish to view different
information at different times (i.e. different users and dates?)


I may have misunderstood the problem, but it seems that the GROUP BY
query would be a good start. For even better response time, you could
consider an indexed view.

--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 23 '05 #2
Your performance problems are probably down to the lack of an appropriate
index (i.e. on EventTime), or maybe that the optimizer is doing its usual
trick of casting the column rather than the constant.

using variables of the same datatype as the column being compared will
ensure that the optimizer doesnt shoot itself in the foot.

SELECT UserID, Count(EvID)
FROM eventlog
WHERE Event = @Event
AND EventTime > @StartTime AND
AND EventTime < @FinishTime
GROUP BY UsedID

covering event and maybe even userID or clustering the eventtime index will
further improve performance but be aware of the knock on storage and
performance implications.

Regards
Mr Tea

"Dan Williams" <dt********@hotmail.com> wrote in message
news:d0*********@hercules.btinternet.com...
We have a bookings table that records various information and for each
booking we record various events that users have performed on that booking
along with when the event occurred.

For example:-

Bookings EventLog
--------- ---------
BookID PK EvID Primary Key
BookDate BookID Foreign Key
BookStart Event
BookFinish, UserID
BookStatus,... EventTime

BookID 1 could have a date of 10/03/05, start time 09:00 and finish time
17:00.
A record gets created in the event table corresponding to which user
created the booking and at what time.
e.g. EvID = 1, BookID = 1, Event = 'Booking Created', UserID = 'dan',
EventTime = '2005/03/09 10:00'

Events get recorded to the EventLog table whenever something happens to
the booking (i.e. the booking status changes, date changes, etc).

We'd like to create a report that calculates the activity of all of our
users. Currently, we loop through all our users and perform individual SQL
queries that count the number of occurrences for a particular event in
between two dates specified.

e.g. SELECT count(EvID) FROM EventLog WHERE UserID = 'dan' AND Event =
'Booking Created' AND EventTime > '2005/03/01' AND EventTime <
'2005/03/10'

This is obviously taking a lot of processing power and resources to
calculate and it slows our application down considerably whenever someone
attempts to view it.

Can anyone recommend a decent way to do this? Ideally, when someone wishes
to view this report (via ASP by the way), rather than it having to
recalculate the information using the datefrom and dateto dates they
specify, it should just displayed the information from a pre-calculated
view? In other words, is it possible to generate the reports overnight or
constantly in real-time, given that people will wish to view different
information at different times (i.e. different users and dates?)

Many thanks for any suggestions you can give me.

Dan Williams.

Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Ranman | last post by:
Hi all, I have a simple problem that hopefully has a simple solution, but I have yet to figure it out. In a patient database, I have a physician test order form that populates a report that is...
1
by: Nathan Bloomfield | last post by:
Does anyone know if there is any documentation which relates to Access2k + ? or can anyone help adjust the code? I am having trouble converting the DAO references. TITLE :INF: How to...
0
by: CSDunn | last post by:
Hello, I have a format issue on an Access 2000 ADP report that I am going to attempt to explain from a 'ten thousand foot view' : I have an Access 2000 ADP report that has a SQL Server 2000...
0
by: Erwin | last post by:
I'm working on a report. Within this report a chart (line chart) is build which shows how many suggestions have been made per servicegroupe. Now I have put such a chart into the report, but the...
7
by: Ellen Manning | last post by:
I've got an A2K report showing students and their costs. Student info is in the main report and costs are in a subreport for each student. The user inputs the program desired then only those...
3
by: tommy | last post by:
I am working with the Invoice report in the Northwind sample database. How can I see the SQL statement that provides the data to the report? Thanks.
6
by: DeniseY | last post by:
I have an Access report that is created on the fly by the user selecting the fields to be included. The Access report comes out fine, but I want it to automatically output to an Excel spreadsheet....
1
by: sonicfun2006 | last post by:
I have SQL Server Database and MS Access 2003 is connected with ODBC. I have very large amount of records in various tables. The database is very dynamic as it changes every minute. I’m trying to...
1
by: Tudor | last post by:
Hi All. I'm new to this forum (as a registree) although I do come by here to find answers which I do always find. I thought I'd post a question and see if anyone can help! I'm developing a DB in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.