Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
I have a field that has PK data from another table stored in it. However there are muliple PKs from this table in the field. I need to sort out the PKs and am having problems with the join. What I have so far is this:
select * from Table1 svc inner join Table2 hm ON (hm.services like ('%,' + Convert(varchar(2),svc.RecID) + ',%'))
The values in hm.services field can be anything like this: (1,) or (1,2,3,4,) etc.The problem is that the first value in this field is not preceded by a ',' so it just ignores them. I still need to know these PKs so I can get an accurate count.Hopefully this isn't too confusing and someone can assist.Thanks in advance!
mwjdavidson
Aged Yak Warrior
735 Posts
Posted - 2007-06-07 : 15:18:33
This is a great example of why storing more than one value in a field is a bad idea, especially on a column that you want to join to. If at all possible, I suggest that you normalise your data such that these values are split across multiple rows.Mark