Using LIKE operator in MSSQL 2005
Posted on 2009-12-30
We are loading new records to a database and we know that there are duplicate ClientIDs [varchar(10)] in the records - some done by human error, others due to large paper files. We're OK with this, but we need a way to append a suffix to the duplicates so they can still be searched.
I have two challenges.
1. Appending the suffix (-2,-3,etc.) I think I can do this with a CURSOR. The first record will never have a suffix, only the duplicates. The suffix sequence will always start with -2 so there is at least one "original ID" record left.
2. The stickier problem is finding the records that have previously been run through this sequence and now have a suffix -- which is why the problem using LIKE emerged.
I can find **exact** duplicates between our working import table and our core table; '021226' will always join to '021226'. But I need to find '021226' LIKE (%column_value%) so I'll find '021226-2' and '021226-3'.
I'm having trouble using the value from a column in a LIKE operation. All help greatly appreciated.