Проблема с ADOQuery
Имеется MS SQL 2000, ADO Delphi7.
используя ADOQuery выполняю запрос
Код:
declare @dat1 datetime, @dat2 datetime
set @dat1=convert (datetime, :dat1)
set @dat2=convert (datetime, :dat2)
select planname, prepaid, paid, price from
(select n.realplanid,
(select planname from Tplan tp where n.realplanid=tp.planid) 'planname',
sum (dat.price) 'price',
sum (dat.rawvolume)/1024/1024 'Paid'
from hnumbers n, datachargebasea dat, contract ct, client cl, contract_number cn
where (dat.processdatetime between @dat1 and @dat2)
and (n.number like '7901497%')
and (n.realplanid=(select realplanid from hnumbers
where changedate=(select max(changedate) from hnumbers h2
where (h2.numberid=dat.numberid) and (changedate<dat.processdatetime)) and (hnumbers.numberid=dat.numberid)))
and (n.changedate=(select max(changedate) from hnumbers h where (h.numberid=dat.numberid) and (h.changedate<dat.processdatetime)))
and (n.numberid=dat.numberid)
and (dat.chargetypeid=1)
and (dat.price>0)
and (n.realplanid in (117, 118, 119, 137, 140, 145, 146, 147, 148))
group by n.realplanid) a
left join
(select n.realplanid,
sum (dat.rawvolume)/1024/1024 'Prepaid'
from hnumbers n, datachargebasea dat, contract ct, client cl, contract_number cn
where (dat.processdatetime between @dat1 and @dat2)
and (n.number like '7901497%')
and (n.realplanid=(select realplanid from hnumbers
where changedate=(select max(changedate) from hnumbers h2
where (h2.numberid=dat.numberid) and (changedate<dat.processdatetime)) and (hnumbers.numberid=dat.numberid)))
and (n.changedate=(select max(changedate) from hnumbers h where (h.numberid=dat.numberid) and (h.changedate<dat.processdatetime)))
and (n.numberid=dat.numberid)
and (dat.chargetypeid=1)
and (dat.price=0)
and (n.realplanid in (117, 118, 119, 137, 140, 145, 146, 147, 148))
group by n.realplanid) b
on a.realplanid=b.realplanid
order by 1
в итоге выдает ошибку что "Время ожидания истекло", я прошелся в профайлире и увидел что у меня к запросу добавляется кое что
exec sp_executesql N'declare @dat1 datetime, @dat2 datetime
set @dat1=convert (datetime, @P1)
set @dat2=convert (datetime, @P2)
Код:
select planname, prepaid, paid, price from
(select n.realplanid,
(select planname from Tplan tp where n.realplanid=tp.planid) ''planname'',
sum (dat.price) ''price'',
sum (dat.rawvolume)/1024/1024 ''Paid''
from hnumbers n, datachargebasea dat, contract ct, client cl, contract_number cn
where (dat.processdatetime between @dat1 and @dat2)
and (n.number like ''7901497%'')
and (n.realplanid=(select realplanid from hnumbers
where changedate=(select max(changedate) from hnumbers h2
where (h2.numberid=dat.numberid) and (changedate<dat.processdatetime)) and (hnumbers.numberid=dat.numberid)))
and (n.changedate=(select max(changedate) from hnumbers h where (h.numberid=dat.numberid) and (h.changedate<dat.processdatetime)))
and (n.numberid=dat.numberid)
and (dat.chargetypeid=1)
and (dat.price>0)
and (n.realplanid in (117, 118, 119, 137, 140, 145, 146, 147, 148))
group by n.realplanid) a
left join
(select n.realplanid,
sum (dat.rawvolume)/1024/1024 ''Prepaid''
from hnumbers n, datachargebasea dat, contract ct, client cl, contract_number cn
where (dat.processdatetime between @dat1 and @dat2)
and (n.number like ''7901497%'')
and (n.realplanid=(select realplanid from hnumbers
where changedate=(select max(changedate) from hnumbers h2
where (h2.numberid=dat.numberid) and (changedate<dat.processdatetime)) and (hnumbers.numberid=dat.numberid)))
and (n.changedate=(select max(changedate) from hnumbers h where (h.numberid=dat.numberid) and (h.changedate<dat.processdatetime)))
and (n.numberid=dat.numberid)
and (dat.chargetypeid=1)
and (dat.price=0)
and (n.realplanid in (117, 118, 119, 137, 140, 145, 146, 147, 148))
group by n.realplanid) b
on a.realplanid=b.realplanid
order by 1
', N'@P1 datetime,@P2 datetime', 'Oct 13 2008 12:00:00:000AM', 'Nov 13 2008 11:59:59:000PM'
Первой и последней строчки в моем запросе нет. Плюс внутри запроса почему-то в местах где у меня апострофы стояли по одному теперь их два.
Дургие запросы выполняются нормально. Причем до этого я в этом же компоненте выполнял другой подобный запрос, тоже с двумя параметрами и все было нормально. Может кто знает что это такое и как с этим бороться??
__________________
Вечность имеет обыкновение проходить очень быстро
|