Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 get some rows

Author  Topic 

uj0e
Starting Member

2 Posts

Posted - 2007-10-28 : 10:15:45
help me please..
I have a problem getting some rows on sql.
the problem is, i've got an employee and money table like this

employee table
Emplid| name | moneyleft|
AFE Alfred 50

Money Table
Emplid| getmoney|
AFE 10
AFE 15

I want to get rows like this
Emplid| name | moneyleft | getmoney| balance|
AFE Alfred 50 10 40
AFE Alfred 40 15 25


The problem is, I must calculate moneyleft field from employee table on the next rows without changed the first value moneyleft field on employee table.
Major problem is software that i used not support declare syntax.
So I must use pure select syntax..
Help Meeee....

dataguru1971
Master Smack Fu Yak Hacker

1464 Posts

Posted - 2007-10-28 : 10:24:28
Is there a date field or another field you can use to identify the order? It might help in setting this up..it can be done I am sure how you need it.

What software do you use that supports Select but not variable declaration?


Go to Top of Page

Koji Matsumura
Posting Yak Master

141 Posts

Posted - 2007-10-28 : 21:48:13
SELECT A.Emplid, A.name, A.moneyleft, B.getmoney,
A.moneyLeft - (SELECT SUM(Z.getmoney) FROM MoneyTable Z WHERE (Include records less than or equal to B using order of Money Table)) AS balance
FROM EmployeeTable A
INNER JOIN MoneyTable B On B.Emplid = A.Emplid
ORDER BY (order of Money Table here)
Go to Top of Page

uj0e
Starting Member

2 Posts

Posted - 2007-11-03 : 11:17:06
Thank's A lot guys..

Go to Top of Page
   

- Advertisement -