Может это поможет?
|Select
|j.iddoc as [Док $Документ.ПриходнаяНакладная],
|$d.Склад as [Склад $Справочник.Склады],
|$d.НомерДок8 as НомерДок8,
|$d.Клиент as [Поставщик $Справочник],
|$d.Кво as Количество,
|$d.СуммаСНДС as Сумма,
|Отбор.ChildID as [ПодчДок $Документ],
|j2.iddocdef as ПодчДок_вид
|from "+?(ЭтоSQL=1,"_","")+"1sjourn j "+?(ЭтоSQL=1,"(nolock)","")+"
|left join $Документ.ПриходнаяНакладная d "+?(ЭтоSQL=1,"(nolock)","")+" on d.iddoc=j.iddoc
|left join "+?(ЭтоSQL=1,"_","")+"1scrdoc Отбор "+?(ЭтоSQL=1,"(nolock)","")+" on Отбор.mdid = ' 0' and Отбор.parentval='O1'+$ВидДокумента36.ПриходнаяНакладная+j.iddoc
|left join "+?(ЭтоSQL=1,"_","")+"1sjourn j2 "+?(ЭтоSQL=1,"(nolock)","")+" on j2.iddoc = Отбор.ChildID
|where j.iddocdef=$ВидДокумента.ПриходнаяНакладная
|"+?(ПустоеЗначение(ВыбПоставщик)=1," "," and $d.Клиент = :Клиент ")+"
|"+?(ПустоеЗначение(ВыбСклад)=1," "," and $d.Склад = :Склад ")+"
|and j.Closed "+?(ЭтоSQL=1,"&1","")+" = 1
|and (Отбор.parentval is null OR j2.Closed "+?(ЭтоSQL=1,"&1","")+" <> 1)
|ORDER BY "+?(ЭтоSQL=1,"left (j.date_time_iddoc,8)","j.date")+"