Subject UNION
Author Dorin Pacurar
I need to make a report based on two views

select * from BALANTA_SINT_CRT
union all
select * from TOT_BALANTA_CRT


CREATE TABLE "BALANTA"
(
"DATA" DATE NOT NULL,
"CONT" VARCHAR(18) NOT NULL,
"FCT" VARCHAR(1) NOT NULL,
"SINTETIC" VARCHAR(7),
"SINID" NUMERIC(18, 2) DEFAULT 0,
"SINIC" NUMERIC(18, 2) DEFAULT 0,
"RD" NUMERIC(18, 2) DEFAULT 0,
"RC" NUMERIC(18, 2) DEFAULT 0,
"SFIND" NUMERIC(18, 2) DEFAULT 0,
"SFINC" NUMERIC(18, 2) DEFAULT 0,
PRIMARY KEY ("DATA", "CONT"))

CREATE TABLE "RULAJE"
( "DATA" DATE NOT NULL,
"CONT" VARCHAR(18) NOT NULL,
"SINTETIC" VARCHAR(8),
"DEBIT" NUMERIC(18, 2) DEFAULT 0,
"CREDIT" NUMERIC(18, 2) DEFAULT 0,
PRIMARY KEY ("DATA", "CONT"))

CREATE VIEW "BALANTA_CRT" (
"DATA", "CONT", "FCT", "SINTETIC", "SINID", "SINIC", "RD",
"RC", "SFIND", "SFINC", "ZD", "ZC"
) AS
SELECT
B.DATA,B.CONT,B.FCT,B.SINTETIC,B.SINID,B.SINIC,B.RD,B.RC,B.SFIND,B.SFINC,
R.DEBIT,R.CREDIT FROM BALANTA B
LEFT JOIN RULAJE R ON B.DATA=R.DATA AND B.CONT=R.CONT
WHERE B.DATA=(SELECT DATALUCRU FROM CONFIG)


CREATE VIEW "BALANTA_SINT_CRT" (
"SINTETIC", "SINID", "SINIC", "RD", "RC", "SFIND", "SFINC",
"ZD", "ZC"
) AS
SELECT SINTETIC,SUM(SINID),SUM(SINIC),SUM(RD),SUM(RC),SUM(SFIND),SUM(SFINC),
SUM(ZD),SUM(ZC) FROM BALANTA_CRT
GROUP BY SINTETIC


CREATE VIEW "TOT_BALANTA_CRT" (
"SINTETIC", "SINID", "SINIC", "RD", "RC", "SFIND", "SFINC",
"ZD", "ZC"
) AS
SELECT 'TOTAL', SUM(SINID),SUM(SINIC),SUM(RD),SUM(RC),SUM(SFIND),SUM(SFINC),
SUM(ZD),SUM(ZC) FROM BALANTA_CRT

When I try to execute the union statement I get:

Dynamic SQL Error
SQL error code = -104
Invalid command
Data type unknown

If I make the statement like

select "SINID", "SINIC", "RD", "RC", "SFIND", "SFINC", "ZD",
"ZC"
from BALANTA_SINT_CRT
union all
select "SINID", "SINIC", "RD", "RC", "SFIND", "SFINC", "ZD",
"ZC"
from TOT_BALANTA_CRT

works fine.

But I need the first column too !

Any help please ?

D5 / IB 6.0.1 / 3.6 Cf

TIA
Dorin