FUNCTION ResolveToMaster (@cUnknown varchar(10)) RETURNS varchar(10) AS begin declare @MasterRef varchar(10) select @MasterRef = null select @MasterRef = (Select Distinct MasterRef from Claim where MasterRef = @cUnknown) if @MasterRef is null begin select @MasterRef = (Select Distinct MasterRef from Claim where CustomerRef = @cUnknown) end if @MasterRef is null begin select @MasterRef = (Select Distinct MasterRef from Claim where ClaimRef = @cUnknown) end Return @MasterRef endwhat I'm trying to achieve here is, to allow a user to enter either of three different numbers and resolve the number to a master reference ( their idea not mine !?? )