Subject Re: Using View with Distinct inside other View crashes server
Author mbabuskov
For those of you who don't have WMONTH, you can use the following,
effect is the same:

SELECT vv.VRSTA,
(select sum(ap.iznos) from apromet ap where ap.vrsta = vv.vrsta and
extract(month from ap.datum)=1),
(select sum(ap.iznos) from apromet ap where ap.vrsta = vv.vrsta and
extract(month from ap.datum)=2),
(select sum(ap.iznos) from apromet ap where ap.vrsta = vv.vrsta and
extract(month from ap.datum)=3),
(select sum(ap.iznos) from apromet ap where ap.vrsta = vv.vrsta and
extract(month from ap.datum)=4),
(select sum(ap.iznos) from apromet ap where ap.vrsta = vv.vrsta and
extract(month from ap.datum)=5),
(select sum(ap.iznos) from apromet ap where ap.vrsta = vv.vrsta and
extract(month from ap.datum)=6),
(select sum(ap.iznos) from apromet ap where ap.vrsta = vv.vrsta and
extract(month from ap.datum)=7),
(select sum(ap.iznos) from apromet ap where ap.vrsta = vv.vrsta and
extract(month from ap.datum)=8),
(select sum(ap.iznos) from apromet ap where ap.vrsta = vv.vrsta and
extract(month from ap.datum)=9),
(select sum(ap.iznos) from apromet ap where ap.vrsta = vv.vrsta and
extract(month from ap.datum)=10),
(select sum(ap.iznos) from apromet ap where ap.vrsta = vv.vrsta and
extract(month from ap.datum)=11),
(select sum(ap.iznos) from apromet ap where ap.vrsta = vv.vrsta and
extract(month from ap.datum)=12),
(select sum(ap.iznos) from apromet ap where ap.vrsta = vv.vrsta)
FROM vv

--- In ib-support@y..., "mbabuskov" <milanb@y...> wrote:
> Hi all,
>
...
> /* ----------- SO FAR SO GOOD -----------
> then I tried to create view for annual report (by months) */
>
> SELECT vv.VRSTA,
> (select sum(ap.iznos) from apromet ap where ap.vrsta = vv.vrsta and
> wmonth(ap.datum)=1),
> (select sum(ap.iznos) from apromet ap where ap.vrsta = vv.vrsta and
> wmonth(ap.datum)=2),
> (select sum(ap.iznos) from apromet ap where ap.vrsta = vv.vrsta and
> wmonth(ap.datum)=3),
> (select sum(ap.iznos) from apromet ap where ap.vrsta = vv.vrsta and
> wmonth(ap.datum)=4),
> (select sum(ap.iznos) from apromet ap where ap.vrsta = vv.vrsta and
> wmonth(ap.datum)=5),
> (select sum(ap.iznos) from apromet ap where ap.vrsta = vv.vrsta and
> wmonth(ap.datum)=6),
> (select sum(ap.iznos) from apromet ap where ap.vrsta = vv.vrsta and
> wmonth(ap.datum)=7),
> (select sum(ap.iznos) from apromet ap where ap.vrsta = vv.vrsta and
> wmonth(ap.datum)=8),
> (select sum(ap.iznos) from apromet ap where ap.vrsta = vv.vrsta and
> wmonth(ap.datum)=9),
> (select sum(ap.iznos) from apromet ap where ap.vrsta = vv.vrsta and
> wmonth(ap.datum)=10),
> (select sum(ap.iznos) from apromet ap where ap.vrsta = vv.vrsta and
> wmonth(ap.datum)=11),
> (select sum(ap.iznos) from apromet ap where ap.vrsta = vv.vrsta and
> wmonth(ap.datum)=12),
> (select sum(ap.iznos) from apromet ap where ap.vrsta = vv.vrsta)
> FROM vv
>
> /*
>
> AND BOOM: IBSERVER caused an invalid page fault in module
> IBSERVER.EXE at 0167:004de348.
> Please note that sometimes it needs to be executed twice in a row
to
> crash the server.
>
> */