私はこれらの3つのテーブルを持っています:
そして、私はこのコードを使用してそれらを結合しています (私は Delphi を使用しています):
ADOQ.SQL.Text := 'select a.IdArt as [Code d''Article], '+
'a.Nom,'+
'Str(a.Prix)+" TND" as Prix, '+
'(select Str(sum(QteEntree))+" "+a.unit from Stock where IdArt = a.IdArt group by IdArt) as [Quantite Entree],' +
'(select Str(sum(Qte))+" "+a.unit from Sold where IdArt = a.IdArt group by IdArt) as [Quantite Vendu],'+
'Str((select sum(QteEntree) from Stock where IdArt = a.IdArt group by IdArt) -' +
'(select sum(Qte) from Sold where IdArt = a.IdArt group by IdArt))+" "+a.unit as [Quantite Existe]'+
'from Article a ';
ご覧のとおり、1 つのテーブルに欠落レコードがあると、DbGrid に Null が返されるので、その欠落レコードを「0」に置き換えたいと考えています。私はこのコードを試しました:
ADOQ.SQL.Text := 'select a.IdArt as [Code d''Article], '+
'a.Nom,'+
'Str(a.Prix)+" TND" as Prix, '+
'(select Str(sum(QteEntree))+" "+a.unit from Stock where IdArt = a.IdArt group by IdArt) as [Quantite Entree],' +
'(select IIF( IsNull(sum(Qte)), "111" , Format( sum(Qte),"00.00") ) from Sold where IdArt = a.IdArt group by IdArt) as [Quantite Vendu],'+
'Str((select sum(QteEntree) from Stock where IdArt = a.IdArt group by IdArt) -' +
'(select sum(Qte) from Sold where IdArt = a.IdArt group by IdArt))+" "+a.unit as [Quantite Existe]'+
'from Article a ';
しかし、このコードは完全に機能しますが、何も変わりません:
ADOQ.SQL.Text := 'Select a.IdArt,IIF(( IsNull( s.qte) ), "00,00" , Format( (s.qte),"00.00") ) from Article a left join sold s on s.IdArt = a.IdArt';
ここで何が間違っていますか?