You're welcome.
>Worked great Sergey, thanks a lot.
>I guess I need to sleep a bit more, brain is shutting down.
>
>>Itr's not clear what 'the first ocurrence' means. If it's MIN value, try
>>SELECT
>> t1.ID,
>> SUBSTRING(T2.NAME,1,20) AS cq_Status,
>> MIN(ISNULL(t6.tar_num,0)) AS tar_num,
>> COUNT(*)
>>...
>>GROUP BY t1.ID, SUBSTRING(T2.NAME,1,20)
>>...
>>
--sb--