DECLARE @UserID INT = 6
DECLARE @Password NVARCHAR(200)='admin1952'
SELECT * FROM
( SELECT TOP 5
ChangedPassword AS ChangedPassword ,
PasswordChangeHistory.Password_Hash AS Password_Hash
FROM PasswordChangeHistory WITH ( NOLOCK )
INNER JOIN [User] U WITH ( NOLOCK )
ON PasswordChangeHistory.UserID = U.Id
WHERE PasswordChangeHistory.UserID = @UserID
) AS result
WHERE PasswordChangeHistory.ChangedPassword = dbo.Encrypt_MD5(@Password)
OR PasswordChangeHistory.Password_Hash = dbo.Encrypt_SHA2(@Password)