Click here to Skip to main content
15,908,115 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hello,

I have created table called Login in sql server where i have column usercode, email and login_date (login_date is datetime type)

So, i created web application using .net. whenever user logged in, i am allowing based userLoged table and i am inserting into login table.

login table
usercode     email          login_date
001          a@gmail.com    2015-11-18 22:02:41.153
001          a@gmail.com    xxx



I have another table called userLoged where i have column usercode,email and web_access

UserLoged table
usercode email         web_access
001         a@gmail.com   Y


Now, if a@gmail.com (001) is not logged in for 45 days, i need to update web_access to be 'N'

how to know if he /she not logged for 45 days.
Posted
Updated 20-Nov-15 10:31am
v3
Comments
ZurdoDev 20-Nov-15 15:58pm    
You are storing the login_date so it should be very easy to know if that login_date was more than 45 days ago. Where exactly are you stuck?
Sergey Alexandrovich Kryukov 20-Nov-15 16:03pm    
And what's the problem? Don't you support the latest logon time for each user? If you do, the solution is a matter of a simple query.
—SA

All you need is to use DATEDIFF[^] function.

SQL
SELECT CASE usercode, login_date, CASE WHEN DATEDIFF(dd, login_date, GETDATE())>45 THEN 'N' ELSE 'Y' END AS Result
FROM (
    SELECT usercode, MAX(login_date) AS login_date 
    FROM [login]
    GROUP BY usercode
) AS T
 
Share this answer
 
v3
It smells like a design problem.
Why you don't store the user LastLoginDdate in UserLoged table, it would simplify things.

Duplicating email in login table can be considered as a bad idea.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900