15,917,005 members
1.00/5 (1 vote)
See more:
how to insert the row from table 2 to table 1 if the ledgerhead, mainledger, subledger of the row doesnot exits on table1. eg

table 1
1 ASSETS ACCUMULATED LOSS - 1245.00 0.00 1245.00
2 ASSETS CASH & BANK BALANCES CASH-IN-HAND 2141639.00 6245.00
3 ASSETS CASH & BANK BALANCES COSYS BANK 4444.00 0.00 4444.00
4 ASSETS CASH & BANK BALANCES GLOBAL IME BANK 12121.00 0.00
5 ASSETS RECEIVABLES INTEREST RECEIVABLES 15000.00 0.00
6 LIABILITIES SAVINGS Double Deposit Saving 3434.00 0.00 3434.00

table 2
1 ASSETS CASH & BANK BALANCES CASH-IN-HAND 2141639.00 6245.00
2 ASSETS CASH & BANK BALANCES GLOBAL IME BANK 12121.00 0.00
3 ASSETS RECEIVABLES INTEREST RECEIVABLES 15000.00 0.00
4 ASSETS CASH & BANK BALANCES KIST BANK LTD. 3434.00 0.00 3434.00
5 LIABILITIES SAVINGS Fixed Deposit 2 Year 0.00 12134.00

that i want to insert the row from table2 is row 4 and 5 because the ledgerhead, mainledger and subledger field of row 4,5 doesnot match to table1 rows data.

Posted
Updated 11-Jun-14 0:47am
v2
[no name] 11-Jun-14 7:28am
Why do you think that the data in the fields has to match before you can INSERT INTO? As long as the data types match there should not be a problem.

## Solution 2

SQL
```INSERT INTO #tempLedgerFinalBalance
SELECT * FROM #tempLedgerPrevious t2 WHERE
NOT EXISTS
(
SELECT * FROM #tempLedgerFinalBalance as t1 WHERE t1.LedgerHead=t2.LedgerHead AND t1.MainLedger=t2.MainLedger AND t1.SubLedger=t2.SubLedger
)```

works fine