Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3392594
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T03:56:34+00:00 2026-05-18T03:56:34+00:00

I have been importing my raw IIS log files into a SQL Server table

  • 0

I have been importing my raw IIS log files into a SQL Server table using the
Log Parser tool for several months now. This is done to enable the writing of
SSRS reports based on this log data.

One of the reports that I am working on is supposed to determine the number of
Visits from each unique IP address. A Visit is defined as an IP address hitting
a page on the site and then making 4 more requests within an hour of each
other. All of the 5 requests are within one Visit to the site. Later on that
night the same IP address hits the site, except that now it’s 3 hours later, so
we count this new activity from the same IP as a new Visit. Here is a sample of
the data:

IPAddress,   RequestDateTime,     UriStem
10.1.1.100,  2010-10-15 13:30:30, /
10.1.1.100,  2010-10-15 13:30:31, /style.css
10.1.1.100,  2010-10-15 13:30:31, /script.js
10.1.1.100,  2010-10-15 13:30:32, /funny.gif
10.1.1.100,  2010-10-15 13:30:33, /picture.jpg
10.1.1.101,  2010-10-15 13:40:50, /page2.html
10.1.1.101,  2010-10-15 13:40:51, /style.css
10.1.1.102,  2010-10-15 14:10:20, /page4.html
10.1.1.102,  2010-10-15 14:10:21, /style.css
10.1.1.100,  2010-10-15 16:55:10, /
10.1.1.100,  2010-10-15 16:55:11, /style.css
10.1.1.100,  2010-10-15 16:55:11, /script.js
10.1.1.100,  2010-10-15 16:55:12, /funny.gif
10.1.1.100,  2010-10-15 16:55:13, /picture.jpg

By looking at the data above I can easily discern that the 10.1.1.100 IP
address has visited the site twice and had 5 hits on each visit. However, I am
at a loss as to how to express that in SQL code. Is there an easy way to group
and count these date ranges by IP address?

I understand that this information can be captured by using tools such as
AWStats, but I do not have the luxury of being able to install Perl on the
systems we use.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T03:56:35+00:00Added an answer on May 18, 2026 at 3:56 am

    Give the code below a trial run. The code groups and numbers the visits from each IP address. Then it looks to see how many “uristem” hits compared with the “threshold” value. I tested the code on a table named “Foo” and you need to check your table and column names prior to running the test.

    DECLARE @threshold INT;  
    SET @threshold = 4;  --this number should not include the initial visit
    DECLARE @lookbackdays int; 
    SET @lookbackdays = 300; 
    
    ;WITH postCTE as  
    (  
    SELECT   
        ipaddress,  
        uristem,  
        requestdatetime,  
        RowNumber = ROW_NUMBER() OVER (ORDER BY ipaddress,requestdatetime ASC)  
    FROM  
        Foo  --put your table name here
    WHERE  
        requestdatetime > GETDATE() - @lookbackdays 
    )  
    --select * from postCTE
    
    SELECT   
        p1.ipaddress AS [ipaddress],   
        p2.RowNumber - p1.RowNumber +1 AS [Requests], 
        p1.requestdatetime AS [DateStart]
    FROM  
        postCTE p1  
    INNER JOIN  
        postCTE p2   
        ON p1.ipaddress = p2.ipaddress   
        AND p1.Rownumber = p2.RowNumber - (@threshold )  
    WHERE  
        DATEDIFF(minute,p1.requestdatetime,p2.requestdatetime) <= 60 
    

    The output of my test on SQL 2008 is

    ipaddress   Requests    DateStart
    10.1.1.100  5   2010-10-15 13:30:30.000
    10.1.1.100  5   2010-10-15 16:55:10.000
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my past applications I have been #importing into my *.h files where needed.
So, there have been several posts here about importing and saving data from an
I have been working with SQL Server as a Developer a while. One thing
I've been working on importing XML into an iPad Core Data application. I have
Content people have been using Word and pasting things into the old unicode system.
I have been getting this error every since importing my existing project into a
I'm importing jquery 1.8.17 js files to Eclipse Indigo, and I have been experiencing
I have been tasked to write a module for importing data into a client's
Have been looking on some tutorials for drawing canvas using SurfaceView, but the only
Have have been trying to make a validator for my xml files. I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.