DataModule1.SiDs_temp.DataSet.CommandText:='select * from (select :t_r as tek_rast, d.N_tel, d.FIO_NAIM, d1.dolg_n, d1.avans_n, d1.abon_pl, d1.mp, d1.dt_mp, d1.abon_pl_i, d1.abon_pl_o, d1.pereraschet, d1.du, d1.itog, ';
DataModule1.SiDs_temp.DataSet.CommandText:=DataModule1.SiDs_temp.DataSet.CommandText+'d1.oplata, d1.dolg_k, d1.avans_k from base_main d, raschet d1 where d.n_tel = d1.n_tel and d1.g_m=:g_m and d.status<>:st_fl order by d1.N_tel) ';
DataModule1.SiDs_temp.DataSet.CommandText:=DataModule1.SiDs_temp.DataSet.CommandText+'union ';
DataModule1.SiDs_temp.DataSet.CommandText:=DataModule1.SiDs_temp.DataSet.CommandText+'select * from (select :r_t as tek_rast, c.N_tel, c.FIO_NAIM, c1.dolg_n, c1.avans_n, c1.abon_pl, c1.mp, c1.dt_mp, c1.abon_pl_i, c1.abon_pl_o, c1.pereraschet, c1.du, c1.itog, ';
DataModule1.SiDs_temp.DataSet.CommandText:=DataModule1.SiDs_temp.DataSet.CommandText+'c1.oplata, c1.dolg_k, c1.avans_k from rastorg_base_main c, rastorg_raschet c1 where c.n_pp = c1.n_pp and c.n_tel = c1.n_tel and c1.g_m=:g_m and c.status<>:st_fl order by c1.N_tel)';
t_r:='T'; r_t:='P';
DataModule1.Sids_temp.DataSet.ParamByName('st_fl').AsString:=st_fl;
DataModule1.Sids_temp.DataSet.ParamByName('g_m').AsString:=g_m;
DataModule1.Sids_temp.DataSet.ParamByName('t_r').AsString:=t_r;
DataModule1.Sids_temp.DataSet.ParamByName('r_t').AsString:=r_t;
Запрос с созданием поля
Код:
Смысл таков: объединяются 2 запроса и еще создается поле. для расторгников поле "Р", для текущих поле "Т". В IBX все работает прекрасно, но в Delphi 7.0 никак не хочет.
Выдает ошибку: Datatype unknown.
В IBX этот же запрос выполняется великолепно.
Код:
select * from
(select 'T' as status, d.N_tel, d.FIO_NAIM, d1.dolg_n, d1.avans_n, d1.abon_pl, d1.mp, d1.dt_mp, d1.abon_pl_i, d1.abon_pl_o, d1.pereraschet, d1.du, d1.itog,
d1.oplata, d1.dolg_k, d1.avans_k from base_main d, raschet d1 where d.n_tel = d1.n_tel and d1.g_m=:g_m and d.status<>:st_fl order by d1.N_tel)
union
select * from
(select 'P' as status, c.N_tel, c.FIO_NAIM, c1.dolg_n, c1.avans_n, c1.abon_pl, c1.mp, c1.dt_mp, c1.abon_pl_i, c1.abon_pl_o, c1.pereraschet, c1.du, c1.itog,
c1.oplata, c1.dolg_k, c1.avans_k from rastorg_base_main c, rastorg_raschet c1 where c.n_pp = c1.n_pp and c.n_tel = c1.n_tel and c1.g_m=:g_m and c.status<>:st_fl order by c1.N_tel)
(select 'T' as status, d.N_tel, d.FIO_NAIM, d1.dolg_n, d1.avans_n, d1.abon_pl, d1.mp, d1.dt_mp, d1.abon_pl_i, d1.abon_pl_o, d1.pereraschet, d1.du, d1.itog,
d1.oplata, d1.dolg_k, d1.avans_k from base_main d, raschet d1 where d.n_tel = d1.n_tel and d1.g_m=:g_m and d.status<>:st_fl order by d1.N_tel)
union
select * from
(select 'P' as status, c.N_tel, c.FIO_NAIM, c1.dolg_n, c1.avans_n, c1.abon_pl, c1.mp, c1.dt_mp, c1.abon_pl_i, c1.abon_pl_o, c1.pereraschet, c1.du, c1.itog,
c1.oplata, c1.dolg_k, c1.avans_k from rastorg_base_main c, rastorg_raschet c1 where c.n_pp = c1.n_pp and c.n_tel = c1.n_tel and c1.g_m=:g_m and c.status<>:st_fl order by c1.N_tel)
FireBird2.0 + IBX + Delphi7.0
DataModule1.Sids_temp.DataSet.ParamByName('st_fl').Value
и чему равно g_m и r_t (в коде не нашел)?
g_m:=DataModule1.SiDs_raschet.fieldByname('g_m').AsString; этот параметр такого вида '2008/05'
t_r:='T';
r_t:='P';
oxotnik333, как ты предложил не идет. выдает ту же самую ошибку :(
Цитата:
st_fl
g_m
t_r
r_t
эти поля в БД все строковые?
st_fl и g_m - строковые, а полей t_r и r_t нет вообще. Смысл такой, чтобы добавить это дополнительное поле в запрос. В первом запросе это поле заполняется как 'T' (текущие), во втором как 'P' (расторгники).
Посморти, пожалуйста, скрин.
Вот как должно быть.
Код:
DataModule1.SiDs_temp.DataSet.CommandText:='select * from (select cast(:r_t as char(1)) as tek_rast, c.N_tel, c.FIO_NAIM, c1.dolg_n, c1.avans_n, c1.abon_pl, c1.mp, c1.dt_mp, c1.abon_pl_i, c1.abon_pl_o, c1.pereraschet, c1.du, c1.itog, ';
DataModule1.SiDs_temp.DataSet.CommandText:=DataModule1.SiDs_temp.DataSet.CommandText+'c1.oplata, c1.dolg_k, c1.avans_k from rastorg_base_main c, rastorg_raschet c1 where c.n_pp = c1.n_pp and c.n_tel = c1.n_tel and c1.g_m=:g_m and c.status<>:st_fl order by c1.N_tel) ';
DataModule1.SiDs_temp.DataSet.CommandText:=DataModule1.SiDs_temp.DataSet.CommandText+'union all ';
DataModule1.SiDs_temp.DataSet.CommandText:=DataModule1.SiDs_temp.DataSet.CommandText+'select * from (select cast(:t_r as char(1)) as tek_rast, d.N_tel, d.FIO_NAIM, d1.dolg_n, d1.avans_n, d1.abon_pl, d1.mp, d1.dt_mp, d1.abon_pl_i, d1.abon_pl_o, d1.pereraschet, d1.du, d1.itog, ';
DataModule1.SiDs_temp.DataSet.CommandText:=DataModule1.SiDs_temp.DataSet.CommandText+'d1.oplata, d1.dolg_k, d1.avans_k from base_main d, raschet d1 where d.n_tel = d1.n_tel and d1.g_m=:g_m and d.status<>:st_fl order by d1.N_tel)';
DataModule1.SiDs_temp.DataSet.CommandText:=DataModule1.SiDs_temp.DataSet.CommandText+'c1.oplata, c1.dolg_k, c1.avans_k from rastorg_base_main c, rastorg_raschet c1 where c.n_pp = c1.n_pp and c.n_tel = c1.n_tel and c1.g_m=:g_m and c.status<>:st_fl order by c1.N_tel) ';
DataModule1.SiDs_temp.DataSet.CommandText:=DataModule1.SiDs_temp.DataSet.CommandText+'union all ';
DataModule1.SiDs_temp.DataSet.CommandText:=DataModule1.SiDs_temp.DataSet.CommandText+'select * from (select cast(:t_r as char(1)) as tek_rast, d.N_tel, d.FIO_NAIM, d1.dolg_n, d1.avans_n, d1.abon_pl, d1.mp, d1.dt_mp, d1.abon_pl_i, d1.abon_pl_o, d1.pereraschet, d1.du, d1.itog, ';
DataModule1.SiDs_temp.DataSet.CommandText:=DataModule1.SiDs_temp.DataSet.CommandText+'d1.oplata, d1.dolg_k, d1.avans_k from base_main d, raschet d1 where d.n_tel = d1.n_tel and d1.g_m=:g_m and d.status<>:st_fl order by d1.N_tel)';