Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SQL puzzle
Message
From
01/10/2001 03:13:11
 
 
To
01/10/2001 02:39:23
Vladimir Zhuravlev
Institute of the Physics of Earth,Russia
Moscow Region, Russia
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Title:
Miscellaneous
Thread ID:
00562396
Message ID:
00562406
Views:
25
Vladimir, use of UDF's inside of the SELECT, REPLACE ALL etc. functions that scan records on internal level, cause a lot of things prepared in the VFP memory internally, specially when you use aggregate functions in the main query. When you try to use another select INSIDE of the SELECT, VFP might be confused (specially by a sum() insode of the subquery). I do not recommend to use that way. This works ok in Oracle (and Ok in SQl Server when you use subqueries). In VFP it is not recommended. For instanse, you might think about why VFP does not allow subquery for a field. Just because it is not prepared for that - you see this in the sample (your sample is just a pure subquery for a field ;) This probably related to the internal VFP SQL query engine.

In addition, you query will run MUCH faster when you split it into 2 parts:
select prhrsh.strr_id, sum(iif(prh.kol!=0,round(prh.smr/prh.kol*prhrsh.kol,2)
    ,00000000.00000000)) as sumTemp;
  from dbf_ck!prh,dbf_ck!prhrsh ;
  where prh.str_id=prhrsh.strp_id GROUP BY prhrsh.strr_id into cursor TempSums

Select sum(nsgn(ndr.kpp)*iif(ck_nspr.type=0,   ;
      <b>TempSums.sumTemp</b>, 00000000.00000)) as sm , ;
      sum(nsgn(ndr.kpp)*iif(ck_nspr.type=2,   ;
      <b>TempSums.sumTemp</b>, 00000000.00000)) as smt  ;
      ,thisform.proc_bar1.sayproc();
      from dbf_ck!rsh,dbf_ck!ck_nspr,dbf_ck!ndr<b>,TempSums</b> ;
      WHERE <b>rsh.str_id=TempSums.strr_id and</b> ck_nspr.product_id = rsh.product_id and not
 empty(rsh.product_id) and;
      empty(rsh.otkl_id) and rsh.doc_id = ndr.doc_id and ndr.dop<m.dt ;
      into cursor inr
You might use also prepare and index the result list of sums by ID at start of your long process for other queries that use this function.

HTH.

>Thanks a lot, Al Doman.
>Index is OK, I made reindex myself and that was first thing, came to my mind.
>As for saving alias, yes, the code was dirty conserning it.
>I just tested as you adviced, the code failed, but the mistake message was didifferent, variable _hzxrt43 was not found ( I never did such variables) . Old fake fixing method still works. I tried don't use array and change it into query incide function and mistake dissapeared. I think, your idea was near to true.
>Vladimir
Vlad Grynchyshyn, Project Manager, MCP
vgryn@yahoo.com
ICQ #10709245
The professional level of programmer could be determined by level of stupidity of his/her bugs

It is not appropriate to say that question is "foolish". There could be only foolish answers. Everybody passed period of time when knows nothing about something.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform