Following is my stored procedure which stores data in two tables namely SuccessfulLogins and FailedLogins

```
ALTER procedure [dbo].[Proc_CheckUser]
 @UserID   VARCHAR(50),
 @Password VARCHAR(50)
 AS

    SET NOCOUNT ON

    DECLARE @ReturnVal VARCHAR(500)
    DECLARE @PasswordOld VARCHAR(50)
    DECLARE @Type NVARCHAR(50)
    DECLARE @IP  NVARCHAR(50)

    SELECT @PasswordOld = Password,@Type=ClientType,@IP=IPAddress
    FROM   Clients
    WHERE  Username = @userid 

    IF (@PasswordOld IS NULL)
      BEGIN
      SET @ReturnVal='1|Incorrect Username'
      INSERT INTO FailedLogins(Username,Password,ClientType,Reason,IPAddress)
      VALUES(@UserID,Hashbytes('SHA1',@Password),@Type,'Invalid Username',@IP)
      END

    ELSE
    BEGIN
    IF (@PasswordOld!=Hashbytes('SHA1',@Password))
      BEGIN
      SET @ReturnVal='1|Incorrect Password'
      INSERT INTO FailedLogins(Username,Password,ClientType,Reason,IPAddress)
      VALUES(@UserID,Hashbytes('SHA1',@Password),@Type,'Invalid Password',@IP)
      END

      ELSE
      BEGIN
      SET @ReturnVal='0|Logged in Successfully' +'|'+ rtrim(cast(@Type as char))
      INSERT INTO SuccessfulLogins(Username,Password,ClientType,Reason,IPAddress)
      VALUES(@UserID,Hashbytes('SHA1',@Password),@Type,'Valid Login Credentials    Provided',@IP)
      END 
      END

      SELECT @ReturnVal

```

The problem here is that whenever I enter an Invalid Username,the stored procedure returns the correct message ie Incorrect Username but it stores NULL values in the fields ClientType and IPAddress in Failed Logins Table

Following is my insert query for Invalid username

```
IF (@PasswordOld!=Hashbytes('SHA1',@Password))
BEGIN
SET @ReturnVal='1|Incorrect Password'
INSERT INTO FailedLogins(Username,Password,ClientType,Reason,IPAddress)
VALUES(@UserID,Hashbytes('SHA1',@Password),@Type,'Invalid Password',@IP)
END

```

Can anyone help me to rectify this.How to check condition for username?

Thanks