i am working on a web analysis project. i am having difficulty with counting hits and visits (a group of hits without a 30 minute break between hits). i decided to build a cursor in order to calculate visits. however, i have no experience with coding cursors and very little experience with both loops and t-sql.
in the cursor, it gets the data from a table that contains the IIS log (used logparser to transfer the logs to sql server). it will then calculate the hits and visits and insert this data into another table that will store a record of total hits and visits for each day.
the problem i am having is that there is no output from this current code. i can't seem to get it to loop back through the if statements and calculate.
any help? - set nocount on
-
-
declare @datetime datetime, @username varchar(30), @holddate datetime, @holdusername varchar(30), @hits int, @visits int, @counter int, @inshits int, @insvisits int
-
-
set @counter = 0
-
declare visitcalculator cursor
-
for select datetime, cs_username from testmetrics.dbo.alldata1 order by cs_username, datetime
-
-
begin
-
open visitcalculator
-
-
-
fetch next from visitcalculator
-
into @datetime, @username
-
-
while @@fetch_status = 0
-
begin
-
if @username = @holdusername --compares username to previous row.
-
begin
-
set @hits = @hits + 1 --count hits
-
set @holdusername = @username
-
set @holddate = @datetime
-
fetch next from visitcalculator into @datetime, @username
-
end
-
-
if @username = @holdusername and datediff(minute, @holddate, @datetime) > 30 --find a break of 30 or more minutes
-
begin
-
set @visits = @visits + 1 --count visits
-
set @holdusername = @username
-
set @holddate = @datetime
-
fetch next from visitcalculator into @datetime, @username
-
end
-
-
if @username != @holdusername
-
begin
-
set @holdusername = @username
-
set @holddate = @datetime
-
fetch next from visitcalculator into @datetime, @username --grab next row.
-
set @visits = @insvisits --transfer visits to insert
-
set @hits = @inshits --transfer hits to insert
-
set @visits = 0 --reset visits
-
set @hits = 0 --reset hits
-
set @counter = @counter + 1 --add to counter
-
end
-
-
if @counter > 1 --write data for each user into table
-
begin
-
insert into testmetrics.dbo.userinfo (username, date, hits, visits) values (@holdusername, @holddate, @inshits, @insvisits)
-
end
-
-
end
-
end
-
close visitcalculator
-
deallocate visitcalculator
1 6854 Sign in to post your reply or Sign up for a free account.
Similar topics |
by: R. Z. |
last post by:
I 've have a stored procedure that compares fields across databases.
In order to do so it requires 2 values it acquires from 2 tables. The
search is based on the ID of the data owner and a subject:
proc_evaluate_results @StudentId = '222222', Course = 'PSY101'
In order to obtain those values I run a cursor accross my records and
SELECT THEM INTO 2 @variables, which then replace 222222 and PSY101
with dynamic values eg.
|
by: Yaron Cohen |
last post by:
Hi,
I would like to ask for your help (I am using only IE5.5).
I have a very big table that I would like to sort.
During the sort I would like the cursor changed to 'wait' state and
back to default state when the sort is over.
The first row of table displays the columns titles when each cell (TD)
|
by: Søren Larsen |
last post by:
In a stored procedure (SP1) I am looping through a cursor with records
from Table1. Each record in the cursor is inserted into Table2.
Insert trigger on Table2 is inserting the record into Table3 (in
another DB).
In the insert trigger on Table3, a series of checks are done on the
inserted record and in case of an error, an email is sent and the
trigger returns.
This break the cursorloop in SP1 and the rest of the records in the
cursor is...
|
by: Jasonsky |
last post by:
I add this code in my InitializeComponent() procedure
Me.Cursor = New Cursor("D:\WindowsApplication1\cur\Yellow.cur")
I don't know why the color of the cursor become "Black and white", even the
original color of my cursor is yellow. Anyone has suggestion? Thanks.
|
by: satishchandra999 |
last post by:
I have SP, which has a cursor iterations. Need to call another SP for
every loop iteration of the cursor. The pseudo code is as follows..
Create proc1 as
Begin
Variable declrations...
declare EffectiveDate_Cursor cursor for
select field1,fld2 from tab1,tab2 where tab1.effectivedate<Getdate()
| |
by: Chris Zopers |
last post by:
Hello,
I've created a stored procedure that loops through a cursor, with the
following example code:
DECLARE curPeriod CURSOR LOCAL for SELECT * FROM tblPeriods
DECLARE @intYear smallint
DECLARE @intPeriod smallint
DECLARE @strTekst varchar(50)
|
by: nareshpaaptan |
last post by:
how to exit from a cursor loop on a specified condition
|
by: yeohyc |
last post by:
Hi All,
I have a problem here. I have done a request for move order it was stored into a custom table with the format:
(O)336126(G)83(I)21823(M)630065120(L)LOT-DISB2P-01(Q)2500
(O)336126(G)83(I)21823(M)630065120(L)LOT-DISB2P-02(Q)2500
(O)336126(G)83(I)21823(M)630065120(L)LOT-DISB2P-03(Q)2500
(O)336126(G)83(I)21823(M)630065120(L)LOT-DISB2P-04(Q)2500
System Reads in (O) = Move Order
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
| |
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |