Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Query duration and query optimization
Message
 
À
Tous
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Titre:
Query duration and query optimization
Versions des environnements
Visual FoxPro:
VFP 8 SP1
OS:
Windows XP SP2
Network:
Windows 2000 Pro
Database:
Visual FoxPro
Divers
Thread ID:
01040935
Message ID:
01040935
Vues:
58
Hi All,
i've a query for stock analysis ( about buying selling quantities and avg prices for its )
i think it takes alot of time and some fields comings null
here is my code, where is the wrong or what should i do for optimization for this queries ?
is there any wrong join ?
Set ENGINEBEHAVIOR 70
Set Deleted On

Local ldOldTime,LdNewTime
ldOldTime=Datetime()

*---
Wait Window " Records are selecting as Filter date(s)........" Nowait At 20,60
Thisform.show_baron()

LcWhereDate =  " BETWEEN(stokhb.tarih,thisform.txttar1.value,thisform.txttar2.value) "
Select * From Addbs(m.gcdata03)+'stokhb' Where &LcWhereDate Into Cursor CrsStokhb
Thisform.show_baroff()

Wait Window " Records are selecting as Filter date(s)........" Nowait At 20,60
Thisform.show_baron()

LcWhereDate1 =  " BETWEEN(stokhb.tarih,thisform.txttar1.value,thisform.txttar2.value) "
LcWhereDate2 =  " stokhb.myguid = stokhd.pmyguid "
LcWhereDate3 = LcWhereDate1 + ' and ' + LcWhereDate2

Select stokhb.myguid,stokhb.iptal,stokhb.tarih,stokhd.* ;
From Addbs(m.gcdata03)+'stokhb',Addbs(m.gcdata03)+'stokhd';
	WHERE &LcWhereDate3 Into Cursor CrsStokhd
Thisform.show_baroff()
*----

lcwhereAlfatMax2=Iif(Empty(Thisform.txtskodu.Value),'.t.','stokhd.skodu=Thisform.txtskodu.Value')
lcwhereAlfatMax3=Iif(Empty(Thisform.txtdepokodu.Value),'.t.','stokhd.depokodu=Thisform.txtdepokodu.Value')
lcwhereAlfatMax4=" stokhb.myguid=stokhd.pmyguid "
lcwhereAlfatMax5=" ! stokhd.stokdusme=.T. And ! stokhb.iptal=.T. "
lcwhereAlfatMax6=" stokhd.fiskodu='001' Or stokhd.fiskodu='003' Or " + ;
	" stokhd.fiskodu='005' Or stokhd.fiskodu='011' Or " + ;
	" stokhd.fiskodu='013' Or stokhd.fiskodu='015' Or " +;
	" stokhd.fiskodu='036' "

lcwhereAlfatMax= lcwhereAlfatMax2 + ' and ' + lcwhereAlfatMax3 + ' and ' + ;
	lcwhereAlfatMax4 + ' and ' + lcwhereAlfatMax5 + ' and ' + lcwhereAlfatMax6


Wait Window " Max buying price findings ........." Nowait At 20,60 && if there is no buyings between filter dates
Thisform.show_baron()

Select stokhb.*,Max(stokhb.tarih) As sonalistarihi,stokhd.skodu,stokhd.depokodu,;
	NVL(stokhd.fiyat,0) As SonAlisFiyati;
	FROM Addbs(m.gcdata03)+'stokhd',Addbs(m.gcdata03)+'stokhb';
	WHERE &lcwhereAlfatMax;
	GROUP By stokhd.skodu,stokhd.depokodu;
	order By stokhd.skodu;
	into Cursor CrsAlFatMax NOFILTER Readwrite


Thisform.show_baroff()
Wait Window " Last Buying prices found........" Nowait At 20,60


lcwhereAlfat1=" BETWEEN(CrsStokhb.tarih,thisform.txttar1.value,thisform.txttar2.value) "
lcwhereAlfat2=Iif(Empty(Thisform.txtskodu.Value),'.t.','CrsStokhd.skodu=Thisform.txtskodu.Value')
lcwhereAlfat3=Iif(Empty(Thisform.txtdepokodu.Value),'.t.','CrsStokhd.depokodu=Thisform.txtdepokodu.Value')
lcwhereAlfat4=" CrsStokhb.myguid=CrsStokhd.pmyguid "
lcwhereAlfat5=" ! CrsStokhd.stokdusme=.T. And ! CrsStokhb.iptal=.T. "
lcwhereAlfat6=" CrsStokhd.fiskodu='001' Or CrsStokhd.fiskodu='003' Or " + ;
	" CrsStokhd.fiskodu='005' Or CrsStokhd.fiskodu='011' Or " + ;
	" CrsStokhd.fiskodu='013' Or CrsStokhd.fiskodu='015' Or " +;
	" CrsStokhd.fiskodu='036' "

lcwhereAlfat= lcwhereAlfat1 + ' and ' + lcwhereAlfat2 + ' and ' + lcwhereAlfat3 + ' and ' + ;
	lcwhereAlfat4 + ' and ' + lcwhereAlfat5 + ' and ' + lcwhereAlfat6

Wait Window " calculating buyings as a Filter........" Nowait At 20,60
Thisform.show_baron()

Select CrsStokhd.skodu,Nvl(Sum(CrsStokhd.girmik),0) As toplamgiren,CrsStokhd.depokodu,;
	NVL( Sum(CrsStokhd.fiyat) / Count(CrsStokhd.skodu) ,0) As AlisOrtFiyati,;
	NVL( Sum(CrsStokhd.girmik) * Sum(CrsStokhd.fiyat) / Count(CrsStokhd.skodu) ,0) As AlisOrtTutari;
	FROM CrsStokhd,CrsStokhb;
	WHERE &lcwhereAlfat;
	GROUP By CrsStokhd.skodu,CrsStokhd.depokodu;
	order By CrsStokhd.skodu;
	into Cursor CrsAlFat NOFILTER Readwrite

Thisform.show_baroff()
Wait Window " buyings calculated as filter........" Nowait At 20,60

lcwhereSatfat1=" BETWEEN(CrsStokhb.tarih,thisform.txttar1.value,thisform.txttar2.value) "
lcwhereSatfat2=	Iif(Empty(Thisform.txtskodu.Value),'.t.','CrsStokhd.skodu=Thisform.txtskodu.Value')
lcwhereSatfat3=	Iif(Empty(Thisform.txtdepokodu.Value),'.t.','CrsStokhd.depokodu=Thisform.txtdepokodu.Value')
lcwhereSatfat4=	" CrsStokhb.myguid=CrsStokhd.pmyguid "
lcwhereSatfat5=	" ! CrsStokhd.stokdusme=.T. And ! CrsStokhb.iptal=.T. "
lcwhereSatfat6=	" CrsStokhd.fiskodu='002' Or CrsStokhd.fiskodu='004' Or " +;
	" CrsStokhd.fiskodu='006' Or CrsStokhd.fiskodu='012' Or " +;
	" CrsStokhd.fiskodu='016' Or CrsStokhd.fiskodu='037' Or " +;
	" CrsStokhd.fiskodu='014' "

lcwhereSatfat= lcwhereSatfat1 + ' and ' + lcwhereSatfat2 + ' and ' + lcwhereSatfat3 + ' and ' + ;
	lcwhereSatfat4 + ' and ' + lcwhereSatfat5 + ' and ' + lcwhereSatfat6

Wait Window " calculating sellings as a Filter........" Nowait At 20,60
Thisform.show_baron()

Select CrsStokhd.skodu,Nvl(Sum(CrsStokhd.cikmik),0) As toplamcikan,CrsStokhd.depokodu,;
	NVL( Sum(CrsStokhd.fiyat) / Count(CrsStokhd.skodu) ,0) As SatisOrtFiyati,;
	NVL( Sum(CrsStokhd.cikmik) * Sum(CrsStokhd.fiyat) / Count(CrsStokhd.skodu) ,0) As SatisOrtTutari;
	FROM CrsStokhd,CrsStokhb ;
	Where &lcwhereSatfat;
	Group By CrsStokhd.skodu,CrsStokhd.depokodu;
	order By CrsStokhd.skodu;
	into Cursor CrsSatFat NOFILTER Readwrite


Thisform.show_baroff()
Wait Window " buyings calculated as filter........" Nowait At 20,60

Wait Window " results Joining ........" Nowait At 20,60
Thisform.show_baron()

Select Stok.skodu,Stok.sadi,Stok.birim1,;
	Stok.birim2,Stok.birim3,Stok.barkod,;
	depo.kod As depokodu,depo.tanim As depoadi,;
	NVL(CrsSatFat.toplamcikan,0) As toplamcikan,;
	NVL(CrsSatFat.SatisOrtFiyati,0) As SatisOrtFiyati,;
	NVL(CrsSatFat.SatisOrtTutari,0) As SatisOrtTutari,;
	NVL(CrsAlFat.toplamgiren,0) As toplamgiren,;
	NVL(CrsAlFatMax.SonAlisFiyati,0) As SonAlisFiyati,;
	NVL(CrsAlFat.AlisOrtFiyati,0) As AlisOrtFiyati,;
	NVL(CrsAlFat.AlisOrtTutari,0) As AlisOrtTutari,;
	NVL( Round( ( ( CrsSatFat.toplamcikan * CrsSatFat.SatisOrtFiyati ) - ;
	( CrsSatFat.toplamcikan * CrsAlFat.AlisOrtFiyati ) ) / ;
	( CrsSatFat.toplamcikan * CrsSatFat.SatisOrtFiyati ) * 100 , 2 ),0) As KarMarji,;
	NVL( ( CrsSatFat.toplamcikan * CrsSatFat.SatisOrtFiyati ) - ;
	( CrsSatFat.toplamcikan * CrsAlFat.AlisOrtFiyati ),0) As OrtalamaKar;
	from Addbs(m.gcdata03)+'Stok';
	left Join CrsSatFat On CrsSatFat.skodu=Stok.skodu;
	inner Join CrsAlFat On CrsAlFat.skodu=Stok.skodu;
	left Join CrsAlFatMax On CrsAlFatMax.skodu=Stok.skodu;
	inner Join Addbs(m.gcdata03)+'depo' On depo.kod=CrsSatFat.depokodu;
	ORDER By Stok.skodu;
	INTO Cursor CrsResult1

Thisform.show_baroff()
Wait Window " Results Joined ........" Nowait At 20,60


Select * From CrsResult1 Order By skodu Into Cursor crsResult NOFILTER

LdNewTime=Datetime()
LnFinal = LdNewTime - ldOldTime
LnFinal= Alltrim(Str(LnFinal))
Wait Window 'Report has been at ' + LnFinal + ' Seconds created.. ' Nowait

Do Form Form\repdialog

=Sys(1104) &&purge cached memory
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform