Subject Re: [firebird-support] Re: Small Update SQL trick (problem)
Author ibrahim bulut
ok,
try this

update customers c
set
totalorders = (select sum(Orders.TotalOrders) from orders orders
where orders.CustomerID = c.id)


----- Original Message -----
From: "majstoru" <majstoru@...>
To: <firebird-support@yahoogroups.com>
Sent: Tuesday, December 27, 2005 10:35 AM
Subject: [firebird-support] Re: Small Update SQL trick (problem)


> Hi,
>
> --- In firebird-support@yahoogroups.com, "ibrahim bulut"
> <i.bulut@i...> wrote:
>>
>> update customers c
>> set
>> totalorders = (select sum(Orders.TotalOrders) from orders orders
>> where orders.CustomerID = c.id)
>> where c.id = :id
>
> this query is OK for one record, but does exsist any solution to
> repeat query n time (n is a nuber of records in the orders table) in
> one SQL statment.
>
> Thanks
>
>>
>>
>> ----- Original Message -----
>> From: "majstoru" <majstoru@y...>
>> To: <firebird-support@yahoogroups.com>
>> Sent: Tuesday, December 27, 2005 12:48 AM
>> Subject: [firebird-support] Small Update SQL trick (problem)
>>
>>
>> > Hi,
>> >
>> > I have a small problem, maybe is not a problem, but an expret
> trick.
>> > I'm using Firebird 2 and I have two tables fex: Customers,
> Orders! I
>> > would like to write a SQL statment to update Customers (field
>> > TotalOrders) from table Orders.
>> > Something like:
>> > UPDATE Customers
>> > SET TotalOrders = SUM(Orders.TotalOrders)
>> > // begin of the problem
>> > The continue of this SQL must update all customers form table
> orders,
>> > something like FOR DO (in delphi).
>> > Important: I need this solution like SQL statment no
> StoredProcedure!
>> >
>> > Thanks for ALL...
>> >
>> >
>> >
>> >
>> >
>> >
>> >
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>> >
>> > Visit http://firebird.sourceforge.net and click the Resources
> item
>> > on the main (top) menu. Try Knowledgebase and FAQ links !
>> >
>> > Also search the knowledgebases at http://www.ibphoenix.com
>> >
>> >
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>> >
>> > Yahoo! Groups Links
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> > __________ NOD32 1.1340 (20051226) Information __________
>> >
>> > This message was checked by NOD32 antivirus system.
>> > http://www.eset.com
>> >
>> >
>>
>
>
>
>
>
>
>
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>
> Visit http://firebird.sourceforge.net and click the Resources item
> on the main (top) menu. Try Knowledgebase and FAQ links !
>
> Also search the knowledgebases at http://www.ibphoenix.com
>
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>
> Yahoo! Groups Links
>
>
>
>
>
>
>
> __________ NOD32 1.1340 (20051226) Information __________
>
> This message was checked by NOD32 antivirus system.
> http://www.eset.com
>
>