Is there a way to get the count where of the columns that are LIKE a column? The CLIENT_ID has a varchar, and any children have the same CLIENT_ID but with a letter at the end (4567 is a parent, 4567A is the first child, 4567B is the second, etc). I am trying to get the count of children for each parent.
I've tried this: SELECT CLIENT_ID, COUNT(*) AS CHILDREN FROM CLIENT GROUP BY CLIENT_ID HAVING CLIENT_ID LIKE CONCAT(CLIENT_ID, '%')
and if his ID is 4567, then grouping on those 10 wouldnt mean they were all meant to be in the same group... they could be, but we can't know for sure :)
The CLIENT_ID column is always unique and will have either a number, like 4567, or if the record is for a child it will always have a letter following the parent number
with cte as ( select '456A' as Child union select '456R' as Child union select '456F' as Child union select '457B' as Child union select '457C' as Child ) select LEFT(Child, LEN(Child) - 1) as Parent, count(*) ChildCount from cte group by LEFT(Child, LEN(Child) - 1)
they did referenced it within ChildId ... you can always join by that
but yes, it would be better if they split it in 2 columns ParentId 457, ChildId A