Is it possible to Concatenate fieldExpressions?

Posts   
 
    
Gabor
User
Posts: 97
Joined: 29-Jan-2005
# Posted on: 30-Mar-2006 07:32:22   

Hi,

I want to change the values of two fields using the UpdateEntitiesDirectly.

Suppose we have to calculate an average sale's price of a given product at the moment of the sale.

In the product table I have a TotalAmount field and a AvgPrice field.

After sale I want to modify the TotalAmount:

TotalAmount=TotalAmount + saledAmount

And calculate the AvgPrice:

AvgPrice=AvgPrice + LastSaledPrice / TotalAmount

Is it possible to do this in one round trip, or change the appropriate fields values, without fetching the entities?

Thanks

Gabor

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 30-Mar-2006 07:45:30   

I think what you want to do can be done in one step as follows:

UPDATE Product
SET TotalAmount = TotalAmount + saledAmount,
AvgPrice = (AvgPrice + LastSaledPrice) / (TotalAmount + saledAmount)
Gabor
User
Posts: 97
Joined: 29-Jan-2005
# Posted on: 30-Mar-2006 08:41:38   

Thanks,

In sql is really very simple, but how to do that in LLBL, using the UpdateEntytiesDirectly?

How can I set two fileld's values? Is it possible to use the changed TotalAmount field value, in expression, that calculates the AvgPrice?

Thanks

Gabor

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 30-Mar-2006 08:51:11   

You should add an expression to each field you want to update before you save the entity or call UpdateEntitiesDirectly.

Please refer to the following thread for more details: http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=2760

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39928
Joined: 17-Aug-2003
# Posted on: 30-Mar-2006 15:08:27   

To get an idea how to execute your expression directly, please see in the manual: Using the generated code -> Field expressions and aggregates -> Expressions in entity updates. This example shows how to update every employee's salary with 10% using an updatedirectly query.

Frans Bouma | Lead developer LLBLGen Pro