Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 10 of 10 total
Thread Updating account balance from transactions
Fri, Mar 23 2007 1:05 PMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

I can get this far and generate the balances

select _fkAccounts , sum(_income) - sum(_expenditure) AS BAL
from transactions
join accounts on accounts._ID = transactions._fkaccounts
where accounts._adjustor = 1
group by _fkaccounts

but how do I put the result into the accounts table?

In DBISAM I'd have probably used a script with a temporary memory table and then joined that to do the update. In ElevateDB I'm lost.

Roy Lambert
Fri, Mar 23 2007 1:36 PMPermanent Link

Dave M
I haven't done this in EDB but, wouldn't you do CREATE TABLE AS <queryexpression>, page 62
EDB sql manual?

dave m


>Roy Lambert wrote:

>but how do I put the result into the accounts table?
>In DBISAM I'd have probably used a script with a temporary memory table and then joined
that to do the update. In ElevateDB I'm lost.

Fri, Mar 23 2007 1:39 PMPermanent Link

Dave M
Or INSERT INTO <TableName> VALUES <QueryExpression>, page 91 EDB sql manual.

dave m
Fri, Mar 23 2007 1:46 PMPermanent Link

Dave M
Oh, you are trying to update.
Maybe I should stop posting while I am behind.
Looks like a CREATE PROCEDURE some variables may be needed.

Dave M

>Dave M wrote

>Or INSERT INTO <TableName> VALUES <QueryExpression>, page 91 EDB sql manual.


Fri, Mar 23 2007 2:01 PMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Dave


That was interesting Smiley

Your final guess is right - I should have said I'm trying to UPDATE.

Roy Lambert
Fri, Mar 23 2007 3:10 PMPermanent Link

Dave M
>Roy Lambert wrote:

>That was interesting Smiley

That was written in a hurry before going out.
Basically, I hate reading other people's code, so mostly I ignore it, if possible.

I only see an UPDATE using values in the manual so, it looks like an update with SELECT
won't work.

Besides a procedure with variables, why can't you do a "script" by reloading a query with
each statement individually?
That's why I suggested CREATE AS, for making a temp table.

dave m
Fri, Mar 23 2007 7:20 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Roy,

<< In DBISAM I'd have probably used a script with a temporary memory table
and then joined that to do the update. In ElevateDB I'm lost. >>

Something like this should work:

UPDATE accounts SET Balance=
  (select  sum(_income) - sum(_expenditure) AS BAL
   from transactions where transactions._fkaccounts=accounts._ID)
WHERE accounts._adjustor = 1

--
Tim Young
Elevate Software
www.elevatesoft.com


Sat, Mar 24 2007 6:09 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Dave


At this point ElevateDB doesn't support scripts Frown

I could do it with several lines of code but then I might as well do it mix'n'match with a combo of sql and navigational code.

Roy Lambert
Sat, Mar 24 2007 6:09 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Tim


Interesting. I don't think it works because it nulls the _Balance column, and I don't think that's right Smiley


Roy Lambert
Mon, Mar 26 2007 10:42 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Roy,

<< Interesting. I don't think it works because it nulls the _Balance column,
and I don't think that's right Smiley>>

It's a bug.  Essentially EDB is not setting up the linked columns properly
when the sub-select isn't live.

--
Tim Young
Elevate Software
www.elevatesoft.com

Image