text: CREATE PROCEDURE dbo.aspnet_Membership_GetUserByName
      @ApplicationName      nvarchar(256),
      @UserName             nvarchar(256),
      @CurrentTimeUtc       datetime,
      @UpdateLastActivity   bit = 0
  AS
  BEGIN
      DECLARE @UserId uniqueidentifier
  
      IF (@UpdateLastActivity = 1)
      BEGIN
          -- select user ID from aspnet_users table
          SELECT TOP 1 @UserId = u.UserId
          FROM    dbo.aspnet_Applications a, dbo.aspnet_Users u, dbo.aspnet_Membership m
          WHERE    LOWER(@ApplicationName) = a.LoweredApplicationName AND
                  u.ApplicationId = a.ApplicationId    AND
                  LOWER(@UserName) = u.LoweredUserName AND u.UserId = m.UserId
  
          IF (@@ROWCOUNT = 0) -- Username not found
              RETURN -1
  
          UPDATE   dbo.aspnet_Users
          SET      LastActivityDate = @CurrentTimeUtc
          WHERE    @UserId = UserId
  
          SELECT m.Email, m.PasswordQuestion, m.Comment, m.IsApproved,
                  m.CreateDate, m.LastLoginDate, u.LastActivityDate, m.LastPasswordChangedDate,
                  u.UserId, m.IsLockedOut, m.LastLockoutDate
          FROM    dbo.aspnet_Applications a, dbo.aspnet_Users u, dbo.aspnet_Membership m
          WHERE  @UserId = u.UserId AND u.UserId = m.UserId 
      END
      ELSE
      BEGIN
          SELECT TOP 1 m.Email, m.PasswordQuestion, m.Comment, m.IsApproved,
                  m.CreateDate, m.LastLoginDate, u.LastActivityDate, m.LastPasswordChangedDate,
                  u.UserId, m.IsLockedOut,m.LastLockoutDate
          FROM    dbo.aspnet_Applications a, dbo.aspnet_Users u, dbo.aspnet_Membership m
          WHERE    LOWER(@ApplicationName) = a.LoweredApplicationName AND
                  u.ApplicationId = a.ApplicationId    AND
                  LOWER(@UserName) = u.LoweredUserName AND u.UserId = m.UserId
  
          IF (@@ROWCOUNT = 0) -- Username not found
              RETURN -1
      END
  
      RETURN 0
  END
  