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.
| 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:UsernameFirstNameLastNameEmailLastActivityDateI 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!ThanksI 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 UsersSET Hits=Hits+1WHERE Users.LastActivityDate >= '12/23/2008 3:10:38 AM' |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
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 KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://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. |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
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? |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
|
|
|