Форум по Delphi программированию

Delphi Sources



Вернуться   Форум по Delphi программированию > Все о Delphi > Базы данных
Ник
Пароль
Регистрация <<         Правила форума         >> FAQ Пользователи Календарь Поиск Сообщения за сегодня Все разделы прочитаны

Ответ
 
Опции темы Поиск в этой теме Опции просмотра
  #1  
Старый 20.11.2008, 09:32
CrazyMan86 CrazyMan86 вне форума
Прохожий
 
Регистрация: 03.09.2008
Адрес: Владикавказ
Сообщения: 13
Репутация: 10
По умолчанию Проблема с 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'

Первой и последней строчки в моем запросе нет. Плюс внутри запроса почему-то в местах где у меня апострофы стояли по одному теперь их два.
Дургие запросы выполняются нормально. Причем до этого я в этом же компоненте выполнял другой подобный запрос, тоже с двумя параметрами и все было нормально. Может кто знает что это такое и как с этим бороться??
__________________
Вечность имеет обыкновение проходить очень быстро
Ответить с цитированием
  #2  
Старый 20.11.2008, 10:52
Qwed86 Qwed86 вне форума
Новичок
 
Регистрация: 12.09.2008
Сообщения: 66
Репутация: 10
По умолчанию

Тут вопрос похоже не по делфи, а по MS SQL Server и его настройках. А так может запрос упростить и методом сокращения и сравнивания с правильно работающими запросами найти строчки или слова вызывающие ошибки.
Вот полезные ссылки вроде по твоему вопросу:
http://www.kuban.ru/forum_new/forum37/arhiv/2898.html
http://www.sql.ru/forum/actualthread...=tdummydataset
Ответить с цитированием
  #3  
Старый 20.11.2008, 14:38
CrazyMan86 CrazyMan86 вне форума
Прохожий
 
Регистрация: 03.09.2008
Адрес: Владикавказ
Сообщения: 13
Репутация: 10
По умолчанию

Да в Скуэле то он проходит. сам запрос в скуэле сначала проверялю
по тем ссылкам что ты дал - я наше лчто таймаут запроса 30 и его никак не поменять. а в другой есть указание на свойства компонента но я пробовал вроде ни фига не работает. буду пытаться =)
__________________
Вечность имеет обыкновение проходить очень быстро
Ответить с цитированием
Ответ


Delphi Sources

Опции темы Поиск в этой теме
Поиск в этой теме:

Расширенный поиск
Опции просмотра

Ваши права в разделе
Вы не можете создавать темы
Вы не можете отвечать на сообщения
Вы не можете прикреплять файлы
Вы не можете редактировать сообщения

BB-коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.
Быстрый переход


Часовой пояс GMT +3, время: 17:20.


 

Сайт

Форум

FAQ

Соглашения

Прочее

 

Copyright © Форум "Delphi Sources" by BrokenByte Software, 2004-2025