--Doviz kuru update

UPDATE STOKHAR SET DovizKuru = (CASE WHEN DovizKodu in ('YP', 'TL') or SonTutar = 0 or SonTutarDov = 0 THEN 1 ELSE SonTutar / SonTutarDov END) 
UPDATE STOKHARDETBAG SET DovizKur = (CASE WHEN DovizKodu in ('YP', 'TL') or Tutar = 0 or DovizTut = 0 THEN 1 ELSE Tutar / DovizTut END)
UPDATE ACARI SET DovizKur = 1 where DOVIZKODU in ('YP', 'TL')
UPDATE KASA SET DovizKur = 1 where DovizKodu in ('YP', 'TL')
go
UPDATE ACARI SET DovizKur = (CASE WHEN BORC >0 AND DovizBorc > 0   THEN BORC / DovizBorc    WHEN ALACAK > 0 and DovizAlacak > 0 THEN ALACAK / DovizAlacak  ELSE 1 END)
UPDATE TEKLIFHAR SET DovizKur = (CASE WHEN DovizKodu in ('YP', 'TL') or SonTutar = 0 or SonTutarDov = 0 THEN 1 ELSE SonTutar / SonTutarDov END) 
UPDATE TEKLIFHARDETBAG SET DovizKur = (CASE WHEN DovizKodu in ('YP', 'TL') or Tutar = 0 or DovizTut = 0 THEN 1 ELSE Tutar / DovizTut END)
go
UPDATE SIPARISHAR SET DovizKur = (CASE WHEN DovizKodu in ('YP', 'TL') or SonTutar = 0 or SonTutarDov = 0 THEN 1 ELSE SonTutar / SonTutarDov END) 
UPDATE SIPARISHARDETBAG SET DovizKur = (CASE WHEN DovizKodu in ('YP', 'TL') or Tutar = 0 or DovizTut = 0 THEN 1 ELSE Tutar / DovizTut END)
UPDATE KASA SET DovizKur = (CASE WHEN BORC > 0 and DovizBorc > 0   THEN BORC / DovizBorc    WHEN ALACAK > 0 and DovizAlacak > 0 THEN ALACAK / DovizAlacak  ELSE 1 END)
go

select   DovizKodu,DovizKuru,max(FaturaTarihi) mxTarih, min(FaturaTarihi) mnTrh from STOKHAR group by DovizKodu,DovizKuru ORDER BY DovizKodu,DovizKuru 
select   DovizKodu,DovizKur,max(FaturaTarihi) mxTarih, min(FaturaTarihi) mnTrh from STOKHARDETBAG group by DovizKodu,DovizKur ORDER BY DovizKodu,DovizKur
select   DOVIZKODU,DovizKur,max(TARIH) mxTarih, min(TARIH) mnTrh from ACARI group by DOVIZKODU,DovizKur ORDER BY DOVIZKODU,DovizKur
select   DovizKodu,DovizKur,max(TARIH) mxTarih, min(TARIH) mnTrh from KASA group by DovizKodu,DovizKur ORDER BY DovizKodu,DovizKur






