text: ﻿CREATE PROCEDURE [dbo].[aspnet_Membership_GetUserByEmail]
      @ApplicationName  nvarchar(256),
      @Email            nvarchar(256)
  AS
  BEGIN
      IF( @Email IS NULL )
          SELECT  u.UserName
          FROM    dbo.aspnet_Applications a, dbo.aspnet_Users u, dbo.aspnet_Membership m
          WHERE   LOWER(@ApplicationName) = a.LoweredApplicationName AND
                  u.ApplicationId = a.ApplicationId    AND
                  u.UserId = m.UserId AND
                  m.LoweredEmail IS NULL
      ELSE
          SELECT  u.UserName
          FROM    dbo.aspnet_Applications a, dbo.aspnet_Users u, dbo.aspnet_Membership m
          WHERE   LOWER(@ApplicationName) = a.LoweredApplicationName AND
                  u.ApplicationId = a.ApplicationId    AND
                  u.UserId = m.UserId AND
                  LOWER(@Email) = m.LoweredEmail
  
      IF (@@rowcount = 0)
          RETURN(1)
      RETURN(0)
  END