I'm running SQL Server 2008, and trying to run some queries on some poorly stored data that I'd rather not go through and try to clean up (millions of rows to deal with). What I have is a log table with some FK data as a comma-separated string in one table, and an integer PK in another table. I'd like to be able to join the FK list of integers to the proper PK ints in the primary table. My query is something like this:
SELECT
L.*
FROM MyLogs L (NOLOCK)
INNER JOIN Details D (NOLOCK) ON L.SearchValue = D.ID
In the above query, L.SearchValue contains "123,456,7890", while D.ID is an integer primary key. Is there any way to join these together in any sort of efficient manner, or should I just accept my fate and start working on a script to break all of these comma separated values into separate rows?