Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think the best way to do this is to summarize your data first, then generate your report.</p> <p>Here's how I'd do it.</p> <ol> <li><p>Create a SummaryTable with the FACTS you want (e.g. UserIP, SessionStart, SessionEnd, PageViews)</p></li> <li><p>Figure out what you consider a new visit (e.g. I think IIS default session timeout is 20 minutes, so any consecutive hit by an IP after 20 minutes I'll consider a new visit.)</p></li> <li><p>Create a cursor to calculate the summarized data based on your rule.</p> <pre><code>-- Summary Data DECLARE @UserIP AS VARCHAR(15) DECLARE @SessionStart AS DateTime DECLARE @SessionEnd AS DateTime DECLARE @PageViews AS INT -- Current Values DECLARE @ThisUserIP AS VARCHAR(15) DECLARE @ThisVisitTime AS DateTime DECLARE @ThisPage AS VARCHAR(100) -- Declare Cusrsor DECLARE StatCursor CURSOR FAST_FORWARD FOR -- Query, make sure you sort by IP/Date so their data is in cronological order SELECT IPAddress, RequestDateTime, UriStem FROM Stats ORDER BY IPAddress, RequestDateTime OPEN StatCursor FETCH NEXT FROM StatCursor INTO @ThisUserIP, @ThisVisitTime, @ThisPage -- Start New Summary SELECT @UserIP = @ThisUserIP, @SessionStart = @ThisVisitTime, @SessionEnd = @ThisVisitTime, @PageViews = 1 FETCH NEXT FROM StatCursor INTO @ThisUserIP, @ThisVisitTime, @ThisPage WHILE @@FETCH_STATUS = 0 BEGIN <pre><code>-- Check rule IF @UserIP = @ThisUserIP AND @ThisVisitTime &amp;lt;= DATEADD(MI,30,@SessionEnd) BEGIN -- Same User and Session / Add to Summary SELECT @PageViews = @PageViews + 1, @SessionEnd = @ThisVisitTime END ELSE BEGIN -- Different User or New User / Write Current Summary and Start New Summary INSERT INTO StatSummary (UserIP, SessionStart, SessionEnd, PageViews) VALUES (@UserIP, @SessionStart, @SessionEnd, @PageViews) SELECT @UserIP = @ThisUserIP, @SessionStart = @ThisVisitTime, @SessionEnd = @ThisVisitTime, @PageViews = 1 END FETCH NEXT FROM StatCursor INTO @ThisUserIP, @ThisVisitTime, @ThisPage </code></pre> END CLOSE StatCursor DEALLOCATE StatCursor </code></pre></li> <li><p>Create a query to get the data you need, example (All time Hits by IP).</p> <p>SELECT UserIP, COUNT(UserIP) FROM StatSummary GROUP BY UserIP</p></li> </ol>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload