By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,766 Members | 1,295 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,766 IT Pros & Developers. It's quick & easy.

Question on a 'Hits' column in User Table

P: 1
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'
Dec 23 '08 #1
Share this Question
Share on Google+
1 Reply


ck9663
Expert 2.5K+
P: 2,878
How do you update LastActivityDate column? Do you update it every time the user access the table? If you do, just update the hits every time you update the LastActivityDate column.

Something like:
Expand|Select|Wrap|Line Numbers
  1.  
  2. UPDATE Users
  3. SET Hits=Hits+1,LastActivityDate = getdate()
  4. WHERE UserName = VariableFromYourSite
  5.  
  6. .
Your options are:

Create a stored proc that will handle all this

or

Build the query from your front end and execute dynamically.

--CK
Dec 23 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.