Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Question on a 'Hits' column in a User Table

Author  Topic 

cpdrews
Starting Member

3 Posts

Posted - 2008-12-23 : 11:46:53
I currently have a User table in my database that has the columns:

Username
FirstName
LastName
Email
LastActivityDate

I created a page on the website in a DotNetNuke reports module where a query is executed that displays all of the user information. I've gotten that to execute properly. I have now created another column in the database table titled 'Hits'

I am trying to get Hits to be incremented by 1 based off of a change in LastActivityDate. So basically each time a user is active on my page a 1 will be added to their 'Hits' in the database table. I've never posted here so if this is in the wrong forum I apologize. Any help would be appreciated!

Thanks

I have tried this and it executes but it will obviously add a hit each time the page is loaded which is not what I am looking for.

UPDATE Users
SET Hits=Hits+1
WHERE Users.LastActivityDate >= '12/23/2008 3:10:38 AM'

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-12-23 : 12:23:58
How will it know the difference between the user being active on the page and the user loading the page?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

cpdrews
Starting Member

3 Posts

Posted - 2008-12-23 : 12:30:04
quote:
Originally posted by tkizer

How will it know the difference between the user being active on the page and the user loading the page?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog



The LastActivityDate changes each time a user logs in. I just want 'Hits' to increment by 1 everytime that LastActivityDate changes.

The UPDATE statement I had been trying updates the query each time that I load this userinfo page. So technically everytime I load the page now it increments by 1 since the time is past the default time I set.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-12-23 : 12:38:29
When you update LastActivityDate change, also update the Hits column. Don't use two separate UPDATE statements as that is inefficient.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

cpdrews
Starting Member

3 Posts

Posted - 2008-12-23 : 13:11:41
quote:
Originally posted by tkizer

When you update LastActivityDate change, also update the Hits column. Don't use two separate UPDATE statements as that is inefficient.

Tara Kizer


This is a site that I am beginning to work on for a company that has already been created. So basically the code that is updating the LastActivityDate in the database just also needs to update the Hits then when a user logs in?
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-12-23 : 13:18:00
That's what I would do.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -