![]() |
|
|
|||||||
| Регистрация | << Правила форума >> | FAQ | Пользователи | Календарь | Поиск | Сообщения за сегодня | Все разделы прочитаны |
![]() |
|
|
Опции темы | Поиск в этой теме | Опции просмотра |
|
#1
|
|||
|
|||
|
Имеется 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'Первой и последней строчки в моем запросе нет. Плюс внутри запроса почему-то в местах где у меня апострофы стояли по одному теперь их два. Дургие запросы выполняются нормально. Причем до этого я в этом же компоненте выполнял другой подобный запрос, тоже с двумя параметрами и все было нормально. Может кто знает что это такое и как с этим бороться?? |
|
#2
|
|||
|
|||
|
Тут вопрос похоже не по делфи, а по MS SQL Server и его настройках. А так может запрос упростить и методом сокращения и сравнивания с правильно работающими запросами найти строчки или слова вызывающие ошибки.
Вот полезные ссылки вроде по твоему вопросу: http://www.kuban.ru/forum_new/forum37/arhiv/2898.html http://www.sql.ru/forum/actualthread...=tdummydataset |
|
#3
|
|||
|
|||
|
Да в Скуэле то он проходит. сам запрос в скуэле сначала проверялю
по тем ссылкам что ты дал - я наше лчто таймаут запроса 30 и его никак не поменять. а в другой есть указание на свойства компонента но я пробовал вроде ни фига не работает. буду пытаться =) |