>>
>>SELECT * FROM depdetail WHERE postingdate = '2016-01-07' AND LEFT(store,4) = @comp_code
>>
>>This works.
>>
>>There's another table called company.
>>The company table has a column called comp_group, which can be blank or contain the code of another row in the table (comp_code)
>>
>>It's a way of grouping related companies for reporting.
>>
>>In addition to the rows pulled above, I'd like the query to pull any rows of related companies.
>>
>>I can do it in the .NET app by looping, but I'd like to do it with a query if possible.
>>
>>Any ideas?
>
>Are you looking for
>
>
>SELECT d.*, c.* FROM depdetail d
>LEFT JOIN companies C ON d.store like c.comp_code + '%' and len(c.comp_code) > 0
>WHERE d.postingdate = '2016-01-07' AND d.store LIKE @comp_code + '%'
>
>
>If not, can you show some data in both tables and how they are related exactly and what do you want to get?
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?
Anyone who does not go overboard- deserves to.
Malcolm Forbes, Sr.