From the description, I would suspect you want an IF EXISTS construct. But really need DDL, sample data and expected results to be sure.
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