>>Maybe this is the question I should have asked:
>>
>>Table company has a comp_code column - a primary key and a comp_group column
>>comp_group can be blank or it can contain the key to itself or another row in the table.
>>
>>How can I find all the members of the group that @comp_code belongs to?
>
>This is still not very clear. Can you post a sample input and desired output? Are you looking for recursive cte?
DECLARE @comp_code CHAR(4)
SELECT @comp_code = '2287'
SELECT a.* FROM
(SELECT * FROM company WHERE compgroup = (SELECT compgroup FROM company WHERE comp_code = @comp_code)) A
OK.. some head scratching gave me this.
It returns all the members of the group that @comp_code belongs to.
I think that will let me solve the rest of it
Thanks for trying to understand me, Naomi.
Anyone who does not go overboard- deserves to.
Malcolm Forbes, Sr.