• Where are you setting the value of @ADDRESS?

    In your code, you have:

    DECLARE @ADR3 VARCHAR(100), @ADDRESS VARCHAR(100)

    SET @ADR3 = (SELECT ADR3

    FROM PAT_NAMES_ADDRESS

    WHERE ADR1 = @ADDRESS)

    So you're declaring @ADDRESS then using it before setting a value. By default it's null, so unless you left out the code where you give @ADDRESS a value, your set boils down to this:

    SET @ADR3 = (SELECT ADR3

    FROM PAT_NAMES_ADDRESS

    WHERE ADR1 = NULL)

    Which will never return rows.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass