Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeOur CommunityOur CommunityGeneral Discuss...General Discuss...Difficulties to find solution for IF/ELSE constructionDifficulties to find solution for IF/ELSE construction
Previous
 
Next
New Post
8/11/2009 9:59 AM
 

Hello,

first i must state i am relatively new to DNN and Transact-SQL scripting so, the following question possible isn't the smartest one. But i can't find a working solution so i hope there is someone out there who can help me.

I am trying to implement an IF/ELSE construction to the following query, which should lock out people who are not changing their password:

Select
  ur.ExpiryDate,
  am.LastPasswordChangedDate,
  am.IsLockedOut,
  au.UserName,
  DateDiff(day, ur.ExpiryDate, GetDate()) As RolExpireDays,
  DateDiff(day, am.LastPasswordChangedDate, GetDate()) As PWExpireDays

From
  aspnet_Users au Left Outer Join
  Users u On au.UserName = u.Username Inner Join
  UserRoles ur On u.UserID = ur.UserID Inner Join
  aspnet_Membership am On au.UserId = am.UserId

Where
  DateDiff(day, ur.ExpiryDate, GetDate()) Between -1 And 0 And
  DateDiff(day, am.LastPasswordChangedDate, GetDate()) < 14


With this IF construction i want to do an update to the results from the above query on the ExpiryDate Column (add 1 year to this date).

With the ELSE construction i want to set the IsLockedOut Column active.

I'ts possible i am completely looking in the wrong direction, so i hope there's someone out there with good ideas...

Thanks in advance!

Mart

 

 
New Post
8/11/2009 4:06 PM
Accepted Answer 

 It looks like you're wanting to do an update, so I'm not really sure where the SELECT statement above plays into the question.

In T-SQL, you can have IF/ELSE statements like this:

   1:  IF @updatingPassword = 1
   2:  BEGIN
   3:      UPDATE UserRoles
   4:      SET ExpiryDate = DATEADD(year, 1, ExpiryDate)
   5:      WHERE RoleId = @roleId and UserId = @userId
   6:  END
   7:  ELSE
   8:  BEGIN
   9:      UPDATE aspnet_Membership
  10:      SET IsLockedOut = 1
  11:      FROM aspnet_Membership am
  12:      JOIN aspnet_Users au ON (am.UserId = am.UserId)
  13:      JOIN Users u ON (au.UserName = u.UserName)
  14:      WHERE u.UserId = @userId
  15:  END

Where @updatingPassword, @roleId, and @userId are variables that you've defined elsewhere.

Hope that helps,


Brian Dukes
Engage Software
St. Louis, MO
866-907-4002
DNN partner specializing in custom, enterprise DNN development.
 
New Post
8/18/2009 5:38 AM
 

Hello Brian,

 

thanks for your quick reply, your answer learned me to look different to this case. The annoying thing is i am new to this, so it's difficult for me to see how to fit in your answer. You are right i want to do an update on results which depends on the query i posted first. Because this update only must take place on these results from tabels which are not directly connected i don't know how to get them without such a SELECT statement...

This is propably where the variables comes in place, if i see it correctly... Can i just set these varibales with DECLARE statements?

Thanks in advance,

 

Mart

 

 
New Post
8/19/2009 6:08 PM
 

 So, I'm still not sure I understand fully, but hopefully this will get you on the right path.

   1:  UPDATE UserRoles
   2:  SET ExpiryDate = DATEADD(year, 1, ur.ExpiryDate)
   3:  FROM
   4:    aspnet_Users au Left Outer Join
   5:    Users u On au.UserName = u.Username Inner Join
   6:    UserRoles ur On u.UserID = ur.UserID Inner Join
   7:    aspnet_Membership am On au.UserId = am.UserId
   8:  WHERE 
   9:    DateDiff(day, ur.ExpiryDate, GetDate()) Between -1 And 0
  10:   
  11:  UPDATE aspnet_Membership
  12:  SET IsLockedOut = 1
  13:  FROM
  14:    aspnet_Users au Left Outer Join
  15:    Users u On au.UserName = u.Username Inner Join
  16:    UserRoles ur On u.UserID = ur.UserID Inner Join
  17:    aspnet_Membership am On au.UserId = am.UserId
  18:  WHERE 
  19:    DateDiff(day, am.LastPasswordChangedDate, GetDate()) < 14

This updates the expiry date if the first where condition is met, and locks them out if the second is met.

Hope that helps,


Brian Dukes
Engage Software
St. Louis, MO
866-907-4002
DNN partner specializing in custom, enterprise DNN development.
 
New Post
8/26/2009 6:42 AM
 

Hello Brian,

 

many thanks, your answer has helped me a lot. I have a working solution with this!

The only difficulty i have left i using an IF/ELSE statement, where in the IF case not one but two 'settings' are true, in this case:

DateDiff(day, ur.ExpiryDate, GetDate()) Between -1 And 0 AND
DateDiff(day, am.LastPasswordChangedDate, GetDate()) < 14


and only if the above are 'untrue' then the ELSE statement will be run:
UPDATE aspnet_Membership  SET IsLockedOut = 1

etc...

Thank you in advance!

Mart



 
Previous
 
Next
HomeHomeOur CommunityOur CommunityGeneral Discuss...General Discuss...Difficulties to find solution for IF/ELSE constructionDifficulties to find solution for IF/ELSE construction


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out