Maalesef SQL server kullanıyorum. (kullanmak zorundayım),
DvCuval diye hesaplatılan bu alan Kod13 isimli gerçek alanın belirli şartlar altındaki toplamlarından oluşuyor ve eğer işlemtipi 4 den işlemturu de 0 dan farklıysa 0 değerini döndürmesini istiyorum. when ile kullanmamın sebebi buydu ve benim DvCuval gibi yaklaşık 10 tane daha aynı sorgu içinde hesaplattığım değer var. sonuçta DvCuval,DvPalet,DvMiktar,DvFason, UretilenCuval,UretilenFason,UretilenMiktar,UretilenPalet v.s gibi değerleri tek sorguda çıkartmak zorundayım. Ama çıkan sorguda Eğer hesaplanan bu değerlerin tümü 0 olursa sorgu neticesinde gelmemesini istiyorum yani DvCuval=0 ve Dvpalet=0 olursa gösterilmemeli ama Invalid Column name (dvcuval) hatası alıyorum. Çünkü Dvcuval gerçekte yok benim oluşturduğum bir işlem. o yüzden ayrı ayrı select kullanamıyorum.
Aslında kodun tamamı şöyle
Kod: Tümünü seç
SELECT Malkodu, Serino, kod4,
SUM(case when tarih<38180 then
case IslemTur when 0 then case IslemTip when 4 then KOD13 else 0 end else 0 end
else 0 end)
-
SUM(case when tarih<38180 then
case IslemTur when 1 then case IslemTip when 1 then KOD13 else 0 end else 0 end
else 0 end) as DvCuval,
SUM(case when tarih<38180 then
case IslemTur when 0 then case IslemTip when 4 then KOD14 else 0 end else 0 end
else 0 end)
-
SUM(case when tarih<38180 then
case IslemTur when 1 then case IslemTip when 1 then KOD14 else 0 end else 0 end
else 0 end) as DvPalet,
SUM(case when tarih<38180 then
case IslemTur when 0 then case IslemTip when 4 then Miktar else 0 end else 0 end
else 0 end)
-
SUM(case when tarih<38180 then
case IslemTur when 1 then case IslemTip when 1 then Miktar else 0 end else 0 end
else 0 end) as DvKG,
SUM(case when tarih<38180 then
case IslemTur when 0 then case IslemTip when 5 then Miktar else 0 end else 0 end
else 0 end)
-
SUM(case when tarih<38180 then
case IslemTur when 1 then case IslemTip when 5 then Miktar else 0 end else 0 end
else 0 end) as DvFason,
SUM(case when tarih=38180 then
case IslemTur when 0 then case IslemTip when 4 then KOD13 else 0 end else 0 end
else 0 end) as UrCuval,
SUM(case when tarih=38180 then
case IslemTur when 0 then case Islemtip when 4 then KOD14 else 0 end else 0 end
else 0 end) AS UrPALET,
SUM(case when tarih=38180 then
case IslemTur when 0 then case IslemTip when 4 then MiKTAR else 0 end else 0 end
else 0 end) AS UrKG,
SUM(case when tarih=38180 then
case IslemTur when 0 then case IslemTip when 5 then miktar else 0 end else 0 end
else 0 end) as UrFason,
SUM(case when tarih=38180 then
case IslemTur when 1 then case IslemTip when 1 then KOD13 else 0 end else 0 end
else 0 end) as CkCuval,
SUM(case when tarih=38180 then
case IslemTur when 1 then case IslemTip when 1 then KOD14 else 0 end else 0 end
else 0 end) as CkPalet,
SUM(case when tarih=38180 then
case IslemTur when 1 then case IslemTip when 1 then Miktar else 0 end else 0 end
else 0 end) as CkKG,
SUM(case when tarih=38180 then
case IslemTur when 1 then case IslemTip when 5 then Miktar else 0 end else 0 end
else 0 end) as CkFason
FROM FINSAT3UN.STI
GROUP BY Malkodu, Serino,kod4
ORDER BY MALKODU
işte bunun sonuna (group by dan önce mesela,
where ((dvCuval<>0) or (dvpalet<>0) or .....) gibi bir filtre koyunca bahsi geçen hatayı alıyorum.