Pascal sum calculator - sum

What is the sum of this one (lets says that the value of x is 2)
I have used pascal to solve this and this is
Program Somme ;
var
n,factoriel,denominateur : longint ;
Numerateur,x,x_sqr,somme_total:real;
begin
writeln('Bienvenue dans le programme : "La somme numerique".');
writeln(' ');
write('Veuillez saisir la valeur numerique de x puis appuyez sur "entre" : ');
read(x);
somme_total:=0;
x_sqr:= 1;
factoriel:=1;
for n:= 1 to 10 do
begin
factoriel:= factoriel*n;
x_sqr:=x*x_sqr;
Numerateur:= n+x_sqr;
denominateur:=(2*factoriel)+1;
somme_total:=somme_total + (Numerateur/denominateur);
end;
writeln('La somme total est : ',somme_total )
end.
here is my teacher answer (I think that it's wrong)
program Somme;
uses wincrt;
var n : integer;
F,P,S,x,somme : real;
Begin
writeln ('Entrez la valeur de x ');
readln(x);
writeln ('===== Calcule de la Somme ====== ');
writeln;
F := 1;
P := 1;
S := 0;
for n := 1 to 10 do
begin
F := F* n;
P := P *x;
S:= (n+P) / (2*F)+1;
writeln ('Resultat de l étiration ', n, ' est égale: ', S:2:2);
somme :=somme +S;
end;
writeln;
writeln ('La somme S est égale: ', S:2:2);
writeln;
end.
so which one is correct?

Related

ORA-06502: PL/SQL: numeric or value error: character to number conversion error in package function

I am trying to create a function that returns pipelined table with input parameters being varchar2, date or number. I am trying to input amount as varchar2 because I can't process it like a number with comma before decimals. Here is body of my package function:
FUNCTION kreiraj_reprogram_rate (p_sifra_kupca VARCHAR2,
p_id_kartice_kupca NUMBER,
p_iznos_s_pdv VARCHAR2,
p_broj_rata NUMBER,
p_frekvencija_dospijeca NUMBER,
p_datum_dospijeca VARCHAR2,
p_datum_dokumenta VARCHAR2)
RETURN reprogram_rate_table
PIPELINED
IS
v_data reprogram_rate_rec;
v_user VARCHAR2 (200) := mc__secure_context.get_context_username ();
v_iznos_rate NUMBER;
v_broj_rate NUMBER;
v_zadnja_rata NUMBER;
v_datum_dokumenta DATE;
v_datum_dospijeca DATE;
BEGIN
write_log_table ('TEST','p_iznos_s_pdv: '|| to_number(p_iznos_s_pdv));
v_datum_dospijeca := TO_DATE (p_datum_dospijeca, 'dd.mm.yyyy');
v_datum_dokumenta := TO_DATE (p_datum_dokumenta, 'dd.mm.yyyy');
v_iznos_rate := ROUND (to_number(p_iznos_s_pdv) / p_broj_rata, 2);
v_zadnja_rata :=
p_iznos_s_pdv - ROUND ((p_broj_rata - 1) * v_iznos_rate, 2);
v_broj_rate := 1;
FOR r IN 1 .. p_broj_rata
LOOP
IF v_broj_rate = p_broj_rata
THEN
v_data.osnovica := ROUND ((v_zadnja_rata / 1.25), 2);
v_data.pdv := ROUND (v_zadnja_rata * 0.2, 2);
v_data.ukupno := v_zadnja_rata;
ELSE
v_data.osnovica := ROUND ((v_iznos_rate / 1.25), 2);
v_data.pdv := ROUND (v_iznos_rate * 0.2, 2);
v_data.ukupno := ROUND (v_iznos_rate, 2);
END IF;
v_data.sifra_kupca := p_sifra_kupca;
v_data.kartica_kupca := p_id_kartice_kupca;
v_data.broj_rate := v_broj_rate;
v_data.datum_dokumenta := v_datum_dokumenta;
v_data.datum_dospijeca := v_datum_dospijeca;
PIPE ROW (v_data);
v_broj_rate := v_broj_rate + 1;
v_datum_dospijeca :=
CASE
WHEN p_frekvencija_dospijeca = 1
THEN
ADD_MONTHS (v_datum_dospijeca, 1)
WHEN p_frekvencija_dospijeca = 3
THEN
ADD_MONTHS (v_datum_dospijeca, 3)
WHEN p_frekvencija_dospijeca = 6
THEN
ADD_MONTHS (v_datum_dospijeca, 6)
WHEN p_frekvencija_dospijeca = 12
THEN
ADD_MONTHS (v_datum_dospijeca, 12)
END;
END LOOP;
END kreiraj_reprogram_rate;
And the error says that error is on the first write_log_table line where I try to convert value 4159,57 to number.
I tried select to_number('4159,57') from dual in SQL developer and it works just fine so I can't figure out what is the catch.
Can someone help?
Thanks.

Recursive query to give a route in postgreSQL

I have to do a recursive function in pSQL to get the following query:
I have a table called tb_route with from_city and to_city
I have another column with the distance in km between different cities.
The table is builded recursively. I have to make a recursive CTE to show the route between two cities (i.e., from 'Santiago de compostela' to 'Saint Jean Pied de Port') showing the total km of the route and the cities where it goes through.
The output has to be something like this:
This is what I've tried:
WITH RECURSIVE cities AS (
SELECT *
FROM textil.tb_route
WHERE to_city_name = 'Santigo de Compostela'
UNION ALL
SELECT e.from_city, e.to_city, e.route, e.km
FROM textil.tb_route e
INNER JOIN cities tb_route ON tb_route.from_city_name = e.from_city
)
SELECT *
FROM cities;
And I had an error like:
ERROR: column e.from_city does not exist
LINE 8: ...JOIN cities tb_route ON tb_route.from_city_name = e.from_cit...
Table:
CREATE TABLE textil.tb_route
(
from_city_name CHARACTER VARYING(120) NOT NULL ,
to_city_name CHARACTER VARYING(120) NOT NULL ,
km_distance_num NUMERIC(5,2) NOT NULL ,
CONSTRAINT pk_route PRIMARY KEY (from_city_name, to_city_name)
);
Data:
INSERT INTO textil.tb_route VALUES
('Saint Jean Pied de Port','Roncesvalles',25.7),
('Somport','Jaca',30.5),
('Roncesvalles','Zubiri',21.5),
('Jaca','Arrés',25),
('Zubiri','Pamplona/Iruña',20.4),
('Arrés','Ruesta',28.7),
('Pamplona/Iruña','Puente la Reina/Gares',24),
('Ruesta','Sangüesa',21.8),
('Puente la Reina/Gares','Estella/Lizarra',22),
('Sangüesa','Monreal',27.25),
('Estella/Lizarra','Torres del Río',29),
('Monreal','Puente la Reina/Gares',31.1),
('Torres del Río','Logroño',20),
('Logroño','Nájera',29.6),
('Nájera','Santo Domingo de la Calzada',21),
('Santo Domingo de la Calzada','Belorado',22.7),
('Belorado','Agés',27.4),
('Agés','Burgos',23),
('Burgos','Hontanas',31.1),
('Hontanas','Boadilla del Camino',28.5),
('Boadilla del Camino','Carrión de los Condes',24.6),
('Carrión de los Condes','Terradillos de los Templarios',26.6),
('Terradillos de los Templarios','El Burgo Ranero',30.6),
('El Burgo Ranero','León',37.1),
('León','San Martín del Camino',25.9),
('San Martín del Camino','Astorga',24.2),
('Astorga','Foncebadón',25.9),
('Foncebadón','Ponferrada',27.3),
('Ponferrada','Villafranca del Bierzo',24.1),
('Villafranca del Bierzo','O Cebreiro',28.4),
('O Cebreiro','Triacastela',21.1),
('Triacastela','Sarria',18.3),
('Sarria','Portomarín',22.4),
('Portomarín','Palas de Rei',25),
('Palas de Rei','Arzúa',28.8),
('Arzúa','Pedrouzo',19.1),
('Pedrouzo','Santiago de Compostela',20),
('Bayona','Ustaritz',14.3),
('Ustaritz','Urdax',21.2),
('Urdax','Elizondo',18.8),
('Elizondo','Berroeta',9.7),
('Berroeta','Olagüe',20.4),
('Olagüe','Pamplona/Iruña',25),
('Irún','Hernani',26.6),
('Hernani','Tolosa',18.9),
('Tolosa','Zerain',33),
('Zerain','Salvatierra/Agurain',28),
('Salvatierra/Agurain','Vitoria/Gasteiz',27.4),
('Vitoria/Gasteiz','La Puebla de Arganzón',18.5),
('La Puebla de Arganzón','Haro',31),
('Haro','Santo Domingo de la Calzada',20),
('Bayona','Irún',33.8),
('Tolosa','Zegama',37.9),
('Zegama','Salvatierra/Agurain',20.1),
('La Puebla de Arganzón','Miranda del Ebro',22.3),
('Miranda del Ebro','Pancorbo',16.7),
('Pancorbo','Briviesca',23.4),
('Briviesca','Monasterio de Rodilla',19.8),
('Monasterio de Rodilla','Burgos',28.5);
```
Here I leave the solution I've get finally:
with recursive caminos(from_city_name, to_city_name, path, total_distance, terminar, ultima_ciudad) as (
-- Consulta base
select to_city_name
,'Saint Jean Pied de Port' -- Cambiar Destino
,concat(to_city_name, concat(' -> ', from_city_name))
,cast(km_distance_num as numeric(8,2))
,0 --No terminar
,from_city_name
from textil.tb_route
where to_city_name = 'Santiago de Compostela' -- Cambiar Origen
union all
-- Consulta recursiva
select caminos.from_city_name
,caminos.to_city_name
,concat(caminos.path, concat( ' -> ', tr.from_city_name))
,cast(caminos.total_distance + tr.km_distance_num as numeric(8,2))
,case when tr.from_city_name = caminos.to_city_name then 1 else 0 end
,tr.from_city_name
from caminos inner join textil.tb_route tr on tr.to_city_name = caminos.ultima_ciudad and caminos.terminar != 1
)
select from_city_name, to_city_name, path, total_distance
from caminos
where 1 = 1
and from_city_name = 'Santiago de Compostela' --Cambiar Origen
and ultima_ciudad = 'Saint Jean Pied de Port' -- Cambiar Destino
;
I understand your question as a graph-walking problem. As described in your questions, edges are directed (meaning that you can travel from from_city_name to to_city_name, but not the other way around).
Here is an approach using a recursive CTE. The idea is to start from a given city, and then follow all possible routes, while keeping track of the overall travel path in an arry. The recursion stops either when a circle is detected, or when the target city is reached. Then, the outer query filters on the successful paths (there may be none, one or several).
with recursive cte as (
select
from_city_name,
to_city_name,
km_distance_num,
array[from_city_name::text, to_city_name::text] path
from tb_route
where from_city_name = 'Saint Jean Pied de Port'
union all
select
r.from_city_name,
r.to_city_name,
c.km_distance_num + r.km_distance_num,
c.path || r.to_city_name::text
from tb_route r
inner join cte c on c.to_city_name = r.from_city_name
where
not r.to_city_name = any(c.path)
and c.from_city_name <> 'Santiago de Compostela'
)
select
path[1] from_city_name,
to_city_name,
km_distance_num,
array_to_string(path, ' > ') path
from cte
where to_city_name = 'Santiago de Compostela';
Demo on DB Fiddle:
from_city_name | to_city_name | km_distance_num | path
:---------------------- | :--------------------- | --------------: | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Saint Jean Pied de Port | Santiago de Compostela | 775.3 | Saint Jean Pied de Port > Roncesvalles > Zubiri > Pamplona/Iruña > Puente la Reina/Gares > Estella/Lizarra > Torres del Río > Logroño > Nájera > Santo Domingo de la Calzada > Belorado > Agés > Burgos > Hontanas > Boadilla del Camino > Carrión de los Condes > Terradillos de los Templarios > El Burgo Ranero > León > San Martín del Camino > Astorga > Foncebadón > Ponferrada > Villafranca del Bierzo > O Cebreiro > Triacastela > Sarria > Portomarín > Palas de Rei > Arzúa > Pedrouzo > Santiago de Compostela

SQL server Trigger no working

I create this trigger, and this select:
SELECT #registro=seccion
FROM dbo.horarios
WHERE materia=#materia
AND seccion=#seccionselect
is not working. This link states that: if the value is not returned from select, previous assign value will be kept. But the record matching this criteria is not found it is returning new data. In the bottom is the output and database values.
CREATE TRIGGER tgr_insertOnHorarios on horarios
AFTER INSERT
AS
BEGIN
DECLARE #materia varchar(7),#aula int,#profesor varchar(7), #seccion varchar(2),#dia varchar(10),
#hora_desde time, #hora_hasta time, #cantidad int, #errores varchar(300), #displayError bit,#registro nchar(10)
SELECT #materia= i.materia FROM inserted i;
SELECT #profesor=i.profesor FROM inserted i;
SELECT #seccion=i.seccion FROM inserted i;
SELECT #dia= i.dia FROM inserted i;
SELECT #hora_desde=i.hora_desde FROM inserted i;
SELECT #hora_hasta= i.hora_hasta FROM inserted i;
SELECT #cantidad= i.cantidad FROM inserted i;
SELECT #aula = i.aula FROM inserted i;
IF (SELECT cantidad_alumnos FROM aulas WHERE codigo=#aula)<#cantidad
BEGIN
SET #errores= 'Contiene mas estudiantes de los permitidos en el aula,'
PRINT #errores
--RAISERROR (#errores,16,1);
ROLLBACK TRANSACTION;
RETURN
END
print #seccion
print #materia
***set #registro='empty'***
print 'registro '+ #registro
**SELECT #registro=seccion FROM dbo.horarios WHERE materia=#materia AND seccion=#seccion**
**print 'registro '+#registro**
IF #registro = #seccion
BEGIN
SET #errores= ' La seccion y la materia ya esta creada, por favor, haga una nueva seccion'
PRINT #errores
--RAISERROR (#errores,16,1);
ROLLBACK TRANSACTION;
RETURN
END
--------------------------------------------
SELECT #registro=profesor FROM horarios WHERE dia=#dia AND hora_desde=#hora_desde AND #hora_hasta=hora_desde AND profesor=#profesor
If #registro IS NOT NULL
BEGIN
SET #errores=' el profesor ya esta asignado en este horario'
PRINT #errores
--RAISERROR (#errores,16,1);
ROLLBACK TRANSACTION;
RETURN
END
--------------------------------------------
declare #dayassig varchar(10),#desde time,#hasta time
SELECT #registro=profesor, #dayassig=dia,#desde=hora_desde,#hasta=hora_hasta FROM horarios WHERE
#dayassig=#dia and
((#desde<=#hora_desde and #hasta>#hora_desde) OR
(#desde<#hora_hasta and #hasta>=#hora_hasta))
IF #registro IS NOT NULL
BEGIN
SET #errores= #errores+' este horario choca'
PRINT #errores
--RAISERROR (#errores,16,1);
ROLLBACK TRANSACTION;
RETURN
END
END
[output]
03 (printing input on insert seccion)
CCI-110 (printing input on insert materia)
registro **empty** (before select)
registro **03** (after select, should not be returning this)
La seccion y la materia ya esta creada, por favor, haga una nueva seccion
[database values]
materia aula profesor seccion dia hora_desde hora_hasta cantidad
CCI-110 501 7722 01 miercoles 12:00:00.0000000 15:00:00.0000000 25
CCI-110 501 7722 01 miercoles 12:00:00.0000000 16:00:00.0000000 25
CCI-110 501 7722 01 miercoles 14:00:00.0000000 16:00:00.0000000 25
How you can see not record matching input seccion 03 andmateria CCI-110, but on [output is printing on register 03]?

Multiple tables in SELECT query

I'm trying to select columns from multiple tables. Here's the code I have:
SELECT
Sum(IIf((tblChain.InitialZone="1"),1,0)) AS SCCH,
tblStatHistory.HomeTeam,
Sum(IIf(([Pentagraph]="HANDB") Or ([Pentagraph]="HANBB") Or ([Pentagraph]="HBCL") Or
([Pentagraph]="KBBW") Or ([Pentagraph]="KBCL") Or ([Pentagraph]="KBIN") Or
([Pentagraph]="KBLO") Or ([Pentagraph]="KBSH") Or ([Pentagraph]="KKBW") Or
([Pentagraph]="KKCL") Or ([Pentagraph]="KKGKN") Or ([Pentagraph]="KKBW") Or
([Pentagraph]="KKGKO") Or ([Pentagraph]="KKGKP") Or([Pentagraph]="KKIN") Or
([Pentagraph]="KKLO") Or ([Pentagraph]="KKSH"),1,0)) AS D,
Sum(IIf(([Pentagraph]="KBBW") Or ([Pentagraph]="KBCL") Or ([Pentagraph]="KBIN") Or
([Pentagraph]="KBLO") Or ([Pentagraph]="KBSH") Or ([Pentagraph]="KKBW") Or
([Pentagraph]="KKCL") Or ([Pentagraph]="KKGKN") Or ([Pentagraph]="KKBW") Or
([Pentagraph]="KKGKO") Or ([Pentagraph]="KKGKP") Or ([Pentagraph]="KKIN") Or
([Pentagraph]="KKLO") Or ([Pentagraph]="KKSH"),1,0)) AS K,
Sum(IIf(([Pentagraph]="KBBW") Or ([Pentagraph]="KKBW"),1,0)) AS K_Back,
Sum(IIf(([Pentagraph]="MACOO") Or ([Pentagraph]="MACOP") Or ([Pentagraph]="MAPAO") Or
([Pentagraph]="MAPAP") Or ([Pentagraph]="MAOL") Or ([Pentagraph]="MAUNO") Or
([Pentagraph]="MAUNP"),1,0)) AS M,
Sum(IIf(([Pentagraph]="MAERO") Or ([Pentagraph]="MAERP") Or ([Pentagraph]="MAUNO") Or
([Pentagraph]="MAUC") Or ([Pentagraph]="MAUNP") Or ([Pentagraph]="MAOL"),1,0)) AS UM,
Sum(IIf(([Pentagraph]="MACOO") Or ([Pentagraph]="MACOP"),1,0)) AS CM,
Sum(IIf(([Pentagraph]="HANDB") Or ([Pentagraph]="HANBB") Or ([Pentagraph]="HBCL"),1,0)) AS H,
Sum(IIf(([Pentagraph]="CBCL") Or ([Pentagraph]="BUCL") Or ([Pentagraph]="TICL"),1,0)) AS C,
Sum(IIf(([Pentagraph]="CBCL"),1,0)) AS C_CSB,
Sum(IIf(([Pentagraph]="BUCL") Or ([Pentagraph]="TICL"),1,0)) AS C_BUTI,
Sum(IIf(([Pentagraph]="CBFP") Or ([Pentagraph]="BUFP") Or ([Pentagraph]="TIFP"),1,0)) AS FP,
Sum(IIf(([Pentagraph]="BUFP") Or ([Pentagraph]="TIFP"),1,0)) AS FP_BUTI,
Sum(IIf(([Pentagraph]="CBFP"),1,0)) AS FP_CSB,
Sum(IIf(([Pentagraph]="CBHO") Or ([Pentagraph]="BUHO") Or ([Pentagraph]="TIHO"),1,0)) AS HO,
Sum(IIf(([Pentagraph]="BUHO") Or ([Pentagraph]="TIHO"),1,0)) AS HO_BUTI,
Sum(IIf(([Pentagraph]="CBHO"),1,0)) AS HO_CSB,
Sum(IIf(([Pentagraph]="IN50"),1,0)) AS I50,
Sum(IIf(([Pentagraph]="GOAL"),1,0)) AS GOAL,
Sum(IIf(([Pentagraph]="BEHI"),1,0)) AS BHND,
Sum(IIf(([Pentagraph]="TACKN") Or ([Pentagraph]="TACKO") Or ([Pentagraph]="TACKP") Or
(([Pentagraph]="RDTDD") And ([ROLE]=1)) Or (([Pentagraph]="TACKL") And ([ROLE]=1)) Or
(([Pentagraph]="RDTAK") And ([ROLE]=1)) Or (([Pentagraph]="DISP") And ([ROLE]=1)),1,0)) AS T,
Sum(IIf(([Pentagraph]="GEHAN") Or ([Pentagraph]="GEHAO") Or ([Pentagraph]="GEHAP") Or ([Pentagraph]="GEHCN") Or ([Pentagraph]="GEHCO") Or([Pentagraph]="GEHCP") Or
([Pentagraph]="GERU") Or ([Pentagraph]="GELON") Or ([Pentagraph]="GELOO") Or ([Pentagraph]="GELOP") Or ([Pentagraph]="GELCN") Or ([Pentagraph]="GELCO") Or ([Pentagraph]="GELCP"),1,0)) AS GB
FROM
tblStatHistory
WHERE
(((tblStatHistory.Period)=IIf(:QTR1,1) Or (tblStatHistory.Period)=IIf(:QTR2,2) Or
(tblStatHistory.Period)=IIf(:QTR3,3) Or (tblStatHistory.Period)=IIf(:QTR4,4)) AND
((tblStatHistory.LogicalZone)=IIf(:ZONEF50,"F") Or (tblStatHistory.LogicalZone)=IIf(:ZONEAM,"S") Or
(tblStatHistory.LogicalZone)=IIf(:ZONEDM,"R") Or (tblStatHistory.LogicalZone)=IIf(:ZONED50,"D")) AND
((tblStatHistory.MatchID)=:GameID) AND ((tblStatHistory.PeriodSecs)>:Seconds))
GROUP BY
tblStatHistory.HomeTeam
ORDER BY
tblStatHistory.HomeTeam DESC;
This part of the very first line is the second table I'm trying to access
Sum(IIf((tblChain.InitialZone="1"),1,0)) AS SCCH
What's happening is if I try write the value of "SCCH" to a variable, it's spitting back that the SCCH field is empty. It also kills the output from the rest of the code, reporting 0 instead of the count of the query.
Any suggestions on how to best implement this?
EDIT: Here is the original code
Procedure TGame.UpdateTeamStats;
var
Query: TADOQuery;
P,Z,T: integer;
begin
try
Query := TADOQuery.Create(nil);
Query.Connection := connection;
Query.Close;
Query.SQL.Add('SELECT tblStatHistory.HomeTeam, Sum(IIf(([Pentagraph]="HANDB") Or ');
Query.SQL.Add('([Pentagraph]="HANBB") Or ([Pentagraph]="HBCL") Or ([Pentagraph]="KBBW") Or ([Pentagraph]="KBCL") Or ');
Query.SQL.Add('([Pentagraph]="KBIN") Or ([Pentagraph]="KBLO") Or ([Pentagraph]="KBSH") Or ');
Query.SQL.Add('([Pentagraph]="KKBW") Or ([Pentagraph]="KKCL") Or ([Pentagraph]="KKGKN") Or ');
Query.SQL.Add('([Pentagraph]="KKBW") Or ([Pentagraph]="KKGKO") Or ([Pentagraph]="KKGKP") Or ');
Query.SQL.Add('([Pentagraph]="KKIN") Or ([Pentagraph]="KKLO") Or ([Pentagraph]="KKSH"),1,0)) AS D, ');
Query.SQL.Add('Sum(IIf(([Pentagraph]="KBBW") Or ([Pentagraph]="KBCL") Or ([Pentagraph]="KBIN") Or ');
Query.SQL.Add('([Pentagraph]="KBLO") Or ([Pentagraph]="KBSH") Or ([Pentagraph]="KKBW") Or ');
Query.SQL.Add('([Pentagraph]="KKCL") Or ([Pentagraph]="KKGKN") Or ([Pentagraph]="KKBW") Or ');
Query.SQL.Add('([Pentagraph]="KKGKO") Or ([Pentagraph]="KKGKP") Or ([Pentagraph]="KKIN") Or ');
Query.SQL.Add('([Pentagraph]="KKLO") Or ([Pentagraph]="KKSH"),1,0)) AS K, ');
Query.SQL.Add('Sum(IIf(([Pentagraph]="MACOO") Or ([Pentagraph]="MACOP") Or ([Pentagraph]="MAPAO") Or ');
Query.SQL.Add('([Pentagraph]="MAPAP") Or ([Pentagraph]="MAOL") Or ([Pentagraph]="MAUNO") Or ');
Query.SQL.Add('([Pentagraph]="MAUNP"),1,0)) AS M, ');
Query.SQL.Add('Sum(IIf(([Pentagraph]="MAERO") Or ([Pentagraph]="MAERP") Or ([Pentagraph]="MAUNO") Or ');
Query.SQL.Add('([Pentagraph]="MAUC") Or ([Pentagraph]="MAUNP") Or ([Pentagraph]="MAOL"),1,0)) AS UM, ');
Query.SQL.Add('Sum(IIf(([Pentagraph]="MACOO") Or ([Pentagraph]="MACOP"),1,0)) AS CM, ');
Query.SQL.Add('Sum(IIf(([Pentagraph]="KBBW") Or ([Pentagraph]="KKBW"),1,0)) AS K_Back, ');
Query.SQL.Add('Sum(IIf(([Pentagraph]="HANDB") Or ([Pentagraph]="HANBB") Or ([Pentagraph]="HBCL"),1,0)) AS H, ');
Query.SQL.Add('Sum(IIf(([Pentagraph]="CBCL") Or ([Pentagraph]="BUCL") Or ([Pentagraph]="TICL"),1,0)) AS C, ');
Query.SQL.Add('Sum(IIf(([Pentagraph]="CBCL"),1,0)) AS C_CSB, ');
Query.SQL.Add('Sum(IIf(([Pentagraph]="BUCL") Or ([Pentagraph]="TICL"),1,0)) AS C_BUTI, ');
Query.SQL.Add('Sum(IIf(([Pentagraph]="CBFP") Or ([Pentagraph]="BUFP") Or ([Pentagraph]="TIFP"),1,0)) AS FP, ');
Query.SQL.Add('Sum(IIf(([Pentagraph]="BUFP") Or ([Pentagraph]="TIFP"),1,0)) AS FP_BUTI, ');
Query.SQL.Add('Sum(IIf(([Pentagraph]="CBFP"),1,0)) AS FP_CSB, ');
Query.SQL.Add('Sum(IIf(([Pentagraph]="CBHO") Or ([Pentagraph]="BUHO") Or ([Pentagraph]="TIHO"),1,0)) AS HO, ');
Query.SQL.Add('Sum(IIf(([Pentagraph]="BUHO") Or ([Pentagraph]="TIHO"),1,0)) AS HO_BUTI, ');
Query.SQL.Add('Sum(IIf(([Pentagraph]="CBHO"),1,0)) AS HO_CSB, ');
Query.SQL.Add('Sum(IIf(([Pentagraph]="IN50"),1,0)) AS I50, ');
Query.SQL.Add('Sum(IIf(([Pentagraph]="GOAL"),1,0)) AS GOAL, ');
Query.SQL.Add('Sum(IIf(([Pentagraph]="BEHI"),1,0)) AS BHND, ');
Query.SQL.Add('Sum(IIf(([Pentagraph]="TACKN") Or ([Pentagraph]="TACKO") Or ([Pentagraph]="TACKP") Or ');
Query.SQL.Add('(([Pentagraph]="RDTDD") And ([ROLE]=1)) Or (([Pentagraph]="TACKL") And ([ROLE]=1)) Or ');
Query.SQL.Add('(([Pentagraph]="RDTAK") And ([ROLE]=1)) Or (([Pentagraph]="DISP") And ([ROLE]=1)),1,0)) AS T, ');
Query.SQL.Add('Sum(IIf(([Pentagraph]="GEHAN") Or ([Pentagraph]="GEHAO") Or ([Pentagraph]="GEHAP") Or ([Pentagraph]="GEHCN") Or ([Pentagraph]="GEHCO") Or([Pentagraph]="GEHCP") Or ');
Query.SQL.Add('([Pentagraph]="GERU") Or ([Pentagraph]="GELON") Or ([Pentagraph]="GELOO") Or ([Pentagraph]="GELOP") Or ([Pentagraph]="GELCN") Or ([Pentagraph]="GELCO") Or ([Pentagraph]="GELCP"),1,0)) AS GB');
Query.SQL.Add('FROM tblStatHistory');
Query.SQL.Add('WHERE (((tblStatHistory.Period)=IIf(:QTR1,1) Or (tblStatHistory.Period)=IIf(:QTR2,2) Or ');
Query.SQL.Add('(tblStatHistory.Period)=IIf(:QTR3,3) Or (tblStatHistory.Period)=IIf(:QTR4,4)) AND ');
Query.SQL.Add('((tblStatHistory.LogicalZone)=IIf(:ZONEF50,"F") Or (tblStatHistory.LogicalZone)=IIf(:ZONEAM,"S") Or ');
Query.SQL.Add('(tblStatHistory.LogicalZone)=IIf(:ZONEDM,"R") Or (tblStatHistory.LogicalZone)=IIf(:ZONED50,"D")) AND ');
Query.SQL.Add('((tblStatHistory.MatchID)=:GameID) AND ((tblStatHistory.PeriodSecs)>:Seconds))');
Query.SQL.Add('GROUP BY tblStatHistory.HomeTeam');
Query.SQL.Add('ORDER BY tblStatHistory.HomeTeam DESC;');
with Query.Parameters.AddParameter do
begin
DataType := ftinteger;
name:= 'GameID';
end;
with Query.Parameters.AddParameter do
begin
DataType := ftinteger;
name:= 'Seconds';
end;
with Query.Parameters.AddParameter do
begin
DataType := ftinteger;
name:= 'QTR1';
end;
with Query.Parameters.AddParameter do
begin
DataType := ftinteger;
name:= 'QTR2';
end;
with Query.Parameters.AddParameter do
begin
DataType := ftinteger;
name:= 'QTR3';
end;
with Query.Parameters.AddParameter do
begin
DataType := ftinteger;
name:= 'QTR4';
end;
with Query.Parameters.AddParameter do
begin
DataType := ftinteger;
name:= 'ZONEF50';
end;
with Query.Parameters.AddParameter do
begin
DataType := ftinteger;
name:= 'ZONEAM';
end;
with Query.Parameters.AddParameter do
begin
DataType := ftinteger;
name:= 'ZONEDM';
end;
with Query.Parameters.AddParameter do
begin
DataType := ftinteger;
name:= 'ZONED50';
end;
Query.Parameters.ParamByName('GameID').Value := GameID;
for P := 0 to 4 do
begin
if updatePeriodCheck(p) then
begin
for Z := 0 to 7 do
begin
SetParameters(P,Z,0,Query.Parameters);
Query.Open;
Query.First;
for T := 0 to 3 do
begin
if T = 1 then Query.Next;
if T < 2 then
Stats[P,Z].Team[T] := PopulateStatsRecord(Query)
else if T = 2 then // Difference
Stats[P,Z].Team[T] := SubtractStatsRecords(Stats[P,Z].Team[1],Stats[P,Z].Team[0])
else if T=3 then begin // Difference Z v Z
if Z = 0 then
Stats[P,Z].Team[T] := Stats[P,Z].Team[2]
else if Z = 1 then
Stats[P,Z].Team[T] := SubtractStatsRecords(Stats[P,1].Team[1],Stats[P,4].Team[0])
else if Z = 2 then
Stats[P,Z].Team[T] := SubtractStatsRecords(Stats[P,2].Team[1],Stats[P,3].Team[0])
else if Z = 3 then
Stats[P,Z].Team[T] := SubtractStatsRecords(Stats[P,3].Team[1],Stats[P,4].Team[0])
else if Z = 4 then
Stats[P,Z].Team[T] := SubtractStatsRecords(Stats[P,4].Team[1],Stats[P,1].Team[0])
else if Z = 5 then
Stats[P,Z].Team[T] := Stats[P,Z].Team[2]
else if z = 6 then
Stats[P,Z].Team[T] := SubtractStatsRecords(Stats[P,6].Team[1],Stats[P,7].Team[0])
else if z = 7 then
Stats[P,Z].Team[T] := SubtractStatsRecords(Stats[P,7].Team[1],Stats[P,6].Team[0]);
end;
end;
Query.Close;
end;
end;
end;
finally
Query.Free;
end;
end;

Statement Error ORA-00923

i have a database that I have populated.
I am now trying to write a SELECT statement:
SELECT + FULL ( fst) full(fs) COUNT(DISTINCT r1.CLIENT_ID || e.CODE || fst.TAB_ID) NB_TAB FROM RATTACHEMENT_DART rd, FLUX_SORTANT fs, FS_TABLEAU fst, equipement e, REFERENTIEL r1, referentiel r2, referentiel pere;
When I try to run the above case statement I recieve the following error:
Erreur commençant à la ligne 4 de la commande : SELECT + FULL ( fst)
full(fs) COUNT(DISTINCT r1.CLIENT_ID || e.CODE || fst.TAB_ID) NB_TAB
FROM RATTACHEMENT_DART rd, FLUX_SORTANT fs, FS_TABLEAU fst, equipement
e, REFERENTIEL r1, referentiel r2, referentiel pere Erreur à la ligne
de commande : 4, colonne : 26 Rapport d'erreur : Erreur SQL :
ORA-00923: mot-clé FROM absent à l'emplacement prévu
00923. 00000 - "FROM keyword not found where expected"
*Cause:
*Action:
If you want to use hints you should use /*+...*/ as below
SELECT /*+ FULL( fst) full(fs)*/ COUNT(DISTINCT r1.CLIENT_ID || e.CODE || fst.TAB_ID) NB_TAB
FROM RATTACHEMENT_DART rd, FLUX_SORTANT fs,
FS_TABLEAU fst, equipement e,
REFERENTIEL r1, referentiel r2, referentiel pere;
See documentation