Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
SQL Query question
Message
De
11/01/2004 03:53:00
 
 
À
11/01/2004 01:44:44
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
00865796
Message ID:
00865806
Vues:
13
>some more info...
>
>I went through an old Joe Celko book, and found the following...
>
>SELECT JobMast.JobNumber, ;
> (SELECT sum(labor.addlabor) FROM INVOICES WHERE INVOICES.JOBNUMBER
> = JOBMAST.JOBNUMBER) AS ADDLABOR, ;
> (SELECT SUM(material.amount) from material where material.jobnumber
> = jobmast.jobnumber) as material ;
> from jobmast group by JOBMAST.JOBNUMBER
>
>That works fine...in SQL Server. However, in VFP (which is where I'm trying to get it to run), I get 'invalid use of subquery'....
>
>???
>
>Kevin

you could try putting the summing subqueries into a function, and including that in the select, e.g.,
** Summing.prg
Function LaborSum(tnJobNumber)
Local laSumLabor(1)
laSumLabor[1]=0
** note: assumed addlabor was column in invoices table....
Select Sum(addlabor) from invoices ;
  where jobnumber=tnJobNumber ;
  into array laSumLabor
Return laSumLabor[1]
EndFunc
Function MaterialSum(tnJobNumber)
Local laSumMat(1)
laSumMat[1]=0
Select Sum(material.amount) from material ;
  where jobnumber=tnJobNumber ;
  into array laSumMat
Return laSumMat[1]
EndFunc

** using it
set proc to summing additive
** note: no need for group by
select jobmast.JobNumber, ;
  LaborSum(jobnumber) as addlabor, ;
  MaterialSum(jobnumber) as material ;
  from JobMast ;
  order by jobnumber ;
  into cursor cuJobNumTotals
Insanity: Doing the same thing over and over and expecting different results.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform