我有這3個表: IIF語句在MS-訪問
,我使用此代碼它們連接在一起(我用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 ';
正如你所看到的那樣,當一個表中有一個缺失記錄時,它會返回Null到DbGrid,因此我想用「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';
我在做什麼錯在這裏?
請不要發佈數據圖片,與甚至是最未格式化的數據樣本相比,它們的用處甚少。樣本可以用來重現問題,但是沒有人會從圖片中輸入數據來測試它。 – Fionnuala
您是否在Ms-Access中測試了上述查詢? – kobik