Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
To use calculated field or not?
Message
De
15/01/2012 11:49:19
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Versions des environnements
Visual FoxPro:
VFP 9 SP1
Divers
Thread ID:
01532936
Message ID:
01532971
Vues:
37
>>>Are you talking about view in SQL Server or VFP? And how would a view help in this case?
>>>
>>I was thinking of SQL Server view, although it will work for VFP as well. We don't want to have calculated field in a table using UDF (as we need to base calculation on another table). The better solution is to use a view where this will be calculated.
>
>I have never, yet, used views in SQL Server. I will make a point to read and learn. Right now I am trying to make my app work on either SQL Server or VFP, using pretty much the same table structures and code. Thank you.


Dmitry,

This is an example how to add po_Freight and po_SalesTax calculated fields to PO, summing them from the invoice table
	create cursor po ;
	(	po_id		I, ;
		po_vendor		c(30), ;
		po_date		D, ;
		po_amount		Y ;
	)
	
	insert into po values (1, 'UT', date(), $100)
	insert into po values (2, 'Google', date()+1, $200)
	
	insert into po values (3, 'Microsoft', date()+2, $200)
	
	create cursor invoice ;
	(	inv_id		I, ;
		inv_po_id		I, ;
		inv_Freight		Y, ;
		inv_SalesTax	Y ;
	)
	
	insert into invoice values(1, 1, $20, $20)
	insert into invoice values(2, 1, $20, $20)
	
	
	insert into invoice values(3, 2, $20, $20)
	insert into invoice values(4, 2, $30, $30)
	
	
	
	select	;
			po_id, ;
			po_vendor, ;
			po_date, ;
			po_amount, ;
			nvl(po_Freight, $0)		as po_Freight, ;
			nvl(po_SalesTax, $0)	as	 po_SalesTax;
		from po ;
			left join ;
				( select ;
						inv_po_id, ;
						sum(inv_Freight) as po_Freight, ;
						sum(inv_SalesTax) as po_SalesTax ;
					from invoice ;
					group by 1 ;
				) X;
				on ( po_id == inv_po_id) 
Gregory
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform