Click here to Skip to main content
15,848,453 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Tengo una tabla llamada tbl_account la cual tiene las siguientes columnas Codes, Account, Debit y Credit

Tengo otra tabla donde hago los registros llamada tbl_entry esta tabla tiene las sihuientes columnas id, recorddate, fk_account, Debit, Credit. Esta tabla tiene una referencia en la tabla tbl_account en fk_account y Codes.

Quiero actualizar la columna Debit y Credit de la tabla tbl_account donde Codes sea igual a fk_account y que a su vez se actualze el Debit y Credit de cada cuenta superior con la suma de sus cuentas hijos

Por ejemplo Codes 11111 = Debit 1000.00 Codes 11112 = Debit 2000.00 y que la cuenta superior que seria Codes 1111 tenga la suma de esas seria 3000.00 y que la cuenta superior tambien tenga su total en Debit y en Credit de las cuentas hijo como Codes 111 = Debit 4000.00 ya que sumaria el total de sus otros hijos que seria 1112 y 1113

Google Translate:
I have a table called tbl_account which has the following columns Codes, Account, Debit and Credit

I have another table where I make the records called tbl_entry, this table has the following columns id, recorddate, fk_account, Debit, Credit. This table has a reference to the tbl_account table in fk_account and Codes.

I want to update the Debit and Credit column of the tbl_account table where Codes is equal to fk_account and in turn the Debit and Credit of each superior account is updated with the sum of its child accounts

For example Codes 11111 = Debit 1000.00 Codes 11112 = Debit 2000.00 and that the superior account that would be Codes 1111 has the sum of those would be 3000.00 and that the superior account also has its total in Debit and in Credit of the child accounts such as Codes 111 = Debit 4000.00 since it would add the total of his other children which would be 1112 and 1113

What I have tried:

Ummm he intentado usar procedimientos almacenados
Google Translate:
Ummm I have tried using stored procedures
Updated 4-Sep-23 19:30pm
OriginalGriff 5-Sep-23 0:31am    
This is an English language site, and we can only accept and answer questions in that language.
I have run this through Google Translate to produce a probably-good version, but you should check it and make sure it does say what you are actually asking.

1 solution

See here: SQL Joins[^] and here: SQL Server UPDATE JOIN Explained By Practical Examples[^]
It's quite possible that you will also need to use SQL GROUP BY Statement[^] to get the totals for each account.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900