\encoding UTF8
select '"'||replace(replace(tetel.sor2,';',','),'"','""')||'"' as sor2, 
       '"'||replace(replace(tetel.lang_0000040e,';',','),'"','""')||'"', 
       '""' as r_leiras, '"'||replace(replace(leiras,';',','),'"','""')||'"' as leiras,
       kisker.egysegar as kisker_ar, nagyker.egysegar as nagyker_ar,
       tetel.afa_kulcs, tetel.mennyisegi_egyseg, null_to_zero(tetel.webboltban_akcios), null_to_zero(tetel.webboltban_akcio_szazalek),
       szeged.szabad as stock_szeged, artand.szabad as stock_artand, tetel.kod
  from tetel
  inner join tetel_egysegar kisker ON kisker.tetel_kod = tetel.kod AND kisker.egysegar_kod = 1
  inner join tetel_egysegar nagyker ON nagyker.tetel_kod = tetel.kod AND nagyker.egysegar_kod = 2
  inner join tetel_raktar szeged ON szeged.tetel_kod = tetel.kod AND szeged.raktar_kod = 1
  inner join tetel_raktar artand ON artand.tetel_kod = tetel.kod AND artand.raktar_kod = 3
  WHERE tetel.webboltban = 1 and tetel.hasznalatban = 1 and tetel.tetel_tipus <> 0
 order by tetel.sor2
