質問

I’m trying to develop a SQL query to help me extract some data from my ASP.NET based website. I'm working on a SQL compact database (sdf) on my ASP.NET based website using WebMatrix.

I’m trying to implement a code in my website to do monthly spring cleaning of the database. I need to delete those accounts which were created by the user but never activated. So to free up the user IDs and manage database size, I thought I’d run a query on the database to get me those accounts which have not been confirmed by the user yet and their creation date has passed 20 days.

The database structure is that my user’s table is called “Users”. It has a UserID (autonumber), Email, FullName, etc. fields.

The table created by ASP’s WebSecurity is called “webpages_Membership”. It has UserID (autonumber), CreationDate, IsConfirmed (whether account has been activated), etc. fields.

I’m not good at developing SQL queries. The problem I’m facing is that when a user is deleted using the Membership.DeleteUser method with argument set to DeleteAllRecords, it deletes the relevant user’s row in my Users table, whereas it does nothing in its own table “webpages_Membership”. When a user tries to sign-in, it simply checks if the Email (the userid) exists in my Users table. So in the long run, there are accounts appearing in “webpages_Membership” which do not exist in “Users” table because they were deleted. People who are familiar with the behavior of WbeSecurity must’ve experienced all this above.

I’m trying to develop a query that will lookup the “webpages_Membership” table, get me those rows which have IsConfirmed field set to False (meaning those accounts not activated yet), and ensure that the UserID field in "webpages_Membership" also exists in "Users" table (this will ensure account is not previously deleted).

役に立ちましたか?

解決

select wm.* from webpages_Membership wm inner join Users u
on wm.UserID = u.UserID 
Where wm.IsConfirmed = 'false'
and DATEADD(dd,20,wm.CreationDate) <= getdate()
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top