Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to find nearest date in select sql
Message
From
20/01/2007 07:02:56
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
01186568
Message ID:
01187316
Views:
22
Then it should be something along these lines:
local ldfirst,ldend,lcfishcode1,lcfischcode2

ldfirst=thisform.txtd1.value
ldend=thisform.txtd2.value
lcfischcode1=[001] && sales fische type
lcfischcode2=[002] && sales fische type

select sum(quantity*price)/sum(quantity) as navgpriceS from ??? where fischetype= m.lcfishcode1 and ;
between(ldate,m.ldfirst,m.ldend) into cursor CrsSales

select sum(quantity*price)/sum(quantity) as navgpriceB from ??? where fischetype= m.lcfishcode2 and ;
between(ldate,m.ldfirst,m.ldend) into cursor CrsBuyings

If _tally=0
   select sum(quantity*price)/sum(quantity) as navgpriceB from ??? where fischetype= m.lcfishcode2 and ;
   m.ldfirst-ldate in (Select Min(m.ldfirst-ldate) from ??? where ldate<=m.ldfirst) into cursor CrsBuyings
EndIf
By the way, actually avg(price) won't work, as it will not take into account the quantity.

And you need to fill in from ???, from which table you want to select....

Bye, Olaf.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform