emi_sastra
asked on
QUEYR USING TABLE DATA AS FILTER
Hi All,
I have below tables :
1. TMLEDGER
AccNo
Amount
2. TMFORM
FormNo
FormAccNo
FromAccNo
ToAccNo
3. TDFORMDATA
FormNo
FormAccNo
FormAmount
I want to query using table 1 and 2 to get result into table 3.
How could I do it ?
Thank you.
I have below tables :
1. TMLEDGER
AccNo
Amount
2. TMFORM
FormNo
FormAccNo
FromAccNo
ToAccNo
3. TDFORMDATA
FormNo
FormAccNo
FormAmount
I want to query using table 1 and 2 to get result into table 3.
How could I do it ?
Thank you.
what is the relation of the account numbers on the form table?
FromAccNo
ToAccNo
how do they relate to
accno on tmledger ?
FromAccNo
ToAccNo
how do they relate to
accno on tmledger ?
is this what you want ?
insert into tdformdata
(formno,formaccno,formamount)
select formno,formaccno,sum(amount)
from tmledger as l
inner join tmform as f
on l.accno between f.fromaccno and f.toaccno
group by formno,formaccno
please specify the relationship between tables ....
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi All,
I am sorry just back.
Thank you.
I am sorry just back.
Thank you.
ASKER
Hi All,
FromAccNo
ToAccNo is related to TMLEDGER AccNo.
Thank you.
FromAccNo
ToAccNo is related to TMLEDGER AccNo.
Thank you.
OK Emi that's fine..
one more thing how do you want to calculate the amount in 3rd table ?
May be you want to subtract the FromAccNo amount to ToAccNo amount or addition , or may you want to directly insert or update the first table amt to third table amt based upon FromAccNo or ToAccNo...?
one more thing how do you want to calculate the amount in 3rd table ?
May be you want to subtract the FromAccNo amount to ToAccNo amount or addition , or may you want to directly insert or update the first table amt to third table amt based upon FromAccNo or ToAccNo...?
ASKER
I want to sum (addition) to the result table base on formaccno.
Thank you.
Thank you.
<< I want to sum (addition) to the result table base on formaccno. >>
ok here is your code..
insert into tdformdata
(FormNo,FormAccNo,FormAmount)
select tm.FormNo,tm.FormAccNo,sum(tl.Amount)
from tmledger as tl
inner join tmform as tf
on tl.AccNo=tf.FormAccNo
group by tf.FormNo,tf.FormAccNo
ASKER
For example :
FormAccNo FromAccNo ToAccNo
100 100.001 100.010
100 100.020 100.090
200 200.001 300.001
Thus Result is sum from AccNo 100 = 100.001 to 100.010 + 100.020 To 100.090
Thank you.
FormAccNo FromAccNo ToAccNo
100 100.001 100.010
100 100.020 100.090
200 200.001 300.001
Thus Result is sum from AccNo 100 = 100.001 to 100.010 + 100.020 To 100.090
Thank you.
then my answer 36480926 should do that...
unless there is a problem with the datatype you have for account...
what data types are you using for the account number columns?
unless there is a problem with the datatype you have for account...
what data types are you using for the account number columns?
ASKER
Yes, I've just tested it.
Thank you very much for your help.
Thank you very much for your help.
ASKER
TMFORM as the table for filtering data from TMLEDGER.
Thank you.