If I understand your question well, you should use any predicate that always evaluates to true, regardless of the parameter values passed to the WHERE . For example WHERE 1 = 1 :
WHERE 1 = 1 AND (@AccountId IS NOT NULL OR AccountId = @AccountId)
Same thing with the @key parameter:
WHERE 1 = 1 AND (@key IS NOT NULL OR New_key = @key)
If the two parameters @key and @AccountId are NULL or one of them, then the WHERE remains valid and returns the entire string as it was not presented.
source share