can i just use sql to get this?
date transfer
20050101 200.00
20050103 -100.00
20050530 95.30
...
SQL to get:
date transferbalance
20050101 200.00200.00
20050103 -100.00100.00
20050530 95.30195.30
date transfer
20050101 200.00
20050103 -100.00
20050530 95.30
...
SQL to get:
date transferbalance
20050101 200.00200.00
20050103 -100.00100.00
20050530 95.30195.30
SELECT table
(SELECT Sum(prev.transfert) as balance ;
FROM table prev ;
WHERE table.date >= prev.date ) ;
FROM table
PS: Version independant. For Fox2x:
SELECT x1.date, x1.transfer, SUM(x2.transfer) as RUN_BAL ;
FROM testdata x1, testdata x2 where x2.date <= x1.date ;
GROUP BY 1,2
20050103 -100.00
20050103 10.00
20050530 95.30
20050530 100.30
then i can't get the right answer
SELECT *,DTOC(date)+STR(recn(),10) as rec FROM detail INTO CURSOR temp
SELECT x1.date, x1.transfer, SUM(x2.transfer) as RUN_BAL ;
FROM temp x1 ;
JOIN temp x2 ON x2.rec <= x1.rec ;
GROUP BY 1,2
in vfp9.0 i can use in one sentece.
can i just use one sentence in vfp 8.0?
[code]
select *,DTOC(date,1)+Sys(2015) as uid from detail into cursor temp nofilter
SELECT x1.date, x1.transfer, SUM(x2.transfer) as RUN_BAL, x1.uid ;
FROM temp x1 ;
JOIN temp x2 ON x2.uid <= x1.uid ;
GROUP BY 1,2,4 ;
order by 1,4
[/code]
Using a single SQL might be possible but I don't recommend.
for instance in vfp9
it can be like this
SELECT x1.date, x1.transfer, SUM(x2.transfer) as RUN_BAL, x1.uid ;
FROM (select *,recno() as uid from detail) x1 ;
JOIN (select *,recno() as uid from detail) x2 ON x2.uid <= x1.uid ;
GROUP BY 1,2,4 ;
order by 1,4
Do you consider this as a single SQL? Syntactically it's but it's not, you now have 3 SQLs. I don't understand why are you forcing yourself to create slower code. Having less lines doesn't make it faster. Not using datetime in the first place is another problem. Use datetime and you wouldn't need complex,slower SQL.
With VFP even it might be much faster if you do it without SQL.
PS: Don't compare VFP's SQL with MSSQL server SQL. With MSSQL you could create much more complex SQL yet much faster.
You're saying MSSQL, how in MSSQL you're keeping such data, no primary key? And in MSSQL there is no date type.
this question i got from my friends,i don; know why he wanted to use one sql either.;-)
thank you verymuch