Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
To use calculated field or not?
Message
 
 
To
15/01/2012 11:49:19
General information
Forum:
Visual FoxPro
Category:
Other
Environment versions
Visual FoxPro:
VFP 9 SP1
Miscellaneous
Thread ID:
01532936
Message ID:
01532972
Views:
27
>>>>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, thank you very much!
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform