PDA

View Full Version : set :Z = geht nicht, ohne das set sehrwohl



dibe
08-11-18, 14:24
Gleich noch eine SQL Frage (danke)

Das liefert eine 1 zurück (interaktiv, strsql)

with a as (select xxkey1, xxkey2, xxkey3
from xxfile where xxma = 14073
and xxan = 0 and xxstat = 2)
select count(*) from(
select yypool from yyfile
where yyma=14073 AND yyAN=0
AND (yykey1, yykey2, yykey3) in(
select xxkey1, xxkey2, xxkey3 from a)
and yymk*1000+yymst <> 999997
group by yypool) as v


ich brauche das als



C/exec-sql
C+ set :Z = (with a as (select xxkey1, xxkey2, xxkey3
C+ from xxfile where xxma = 14073
C+ and xxan = 0 and xxstat = 2)
C+ select count(*) from(
C+ select yypool from yyfile
C+ where yyma=14073 AND yyAN=0
C+ AND (yykey1, yykey2, yykey3) in(
C+ select xxkey1, xxkey2, xxkey3 from a)
C+ and yymk*1000+yymst <> 999997
C+ group by yypool) as v )
C/end exec


Das bricht zur Laufzeit ab und erzeugt sogar einen dump

Was ist falsch?

Danke

Fuerchau
08-11-18, 16:24
Ggf. wird ein Fullselect beim Set nicht unterstützt.
Eine Set-Anweisung entspricht einem skalaren Subselect und da ist With auch nicht erlaubt.

Aber dies geht wohl ebenso:



C/exec-sql
C+ with a as (select xxkey1, xxkey2, xxkey3
C+ from xxfile where xxma = 14073
C+ and xxan = 0 and xxstat = 2)
C+ select count(*) into :Z
c+ from(
C+ select yypool from yyfile
C+ where yyma=14073 AND yyAN=0
C+ AND (yykey1, yykey2, yykey3) in(
C+ select xxkey1, xxkey2, xxkey3 from a)
C+ and yymk*1000+yymst <> 999997
C+ group by yypool) as v
C/end exec

dibe
12-11-18, 08:52
Danke, so hat es funktioniert!

Dietlinde Beck

Fuerchau
12-11-18, 09:26
Bedenke dabei nur, dass der Count u.U. auch NULL zurückgeben kann wenn keine Daten gefunden werden. In diesem Fall wäre ein NULL-Anzeiger schon hilfreich, denn ein negativer SQLCODE kann auch andere Gründe haben. Aber SQLCODE und/oder NULL-Anzeiger abzufragen macht da schon Sinn.

BenderD
12-11-18, 10:15
... count sollte schon was zurück geben, bei leerem ResultSet dann 0.

D*B

Fuerchau
12-11-18, 11:05
Nein, meine Erfahrung besagt, dass Count auch NULL zurückgibt, sonst hätte ich es nicht erwähnt.
Mag sein, dass dies ein IBM-SQL-Fehler ist, aber das hat mich dann nie interessiert.

andreaspr@aon.at
12-11-18, 17:59
Das würde mich jetzt auch sehr wundern wenn ein count NULL zurück liefert.
Auch in der Doku steht auch extra "The result cannot be null".

Fuerchau
13-11-18, 08:14
Dann werde ich den SQL nochmal raussuchen, vielleicht ist der Grund dann erkennbar.