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 2008 Forums
 Transact-SQL (2008)
 UPDATING ROWS USING VALUE GET FROM TABLE

Author  Topic 

Crz_Gordo
Starting Member

1 Post

Posted - 2013-11-08 : 03:23:22
Hi to all,
Im designing a Accounting software a Trial Balance.
The logic is like this.

TRIAL BALANCE SHEET
Account Code Amount
10000
10000-10100
10000-10200
10000-10200-10201

SQL TABLE
ACOUNTCODE TRAILS AMOUNT
10000 00000
10100 10000-10100
10200 10000-10200
10201 10000-10200-10201

What i want is if i update the table using the SET AMOUNT = 100 WHERE ACCOUNTCODE = '10201' it will update the AMOUNT field of ACCOUNTCODE 10000 , 10200 , 10201

OUTPUT
ACOUNTCODE TRAILS AMOUNT
10000 00000 100.00
10100 10000-10100
10200 10000-10200 100.00
10201 10000-10200-10201 100.00

i tried CONTAINS function but it didnt work.

what function i will use?

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-11-08 : 04:30:27
[code]
UPDATE t1
SET AMOUNT = 100.00
FROM Table t1
INNER JOIN Table t2
ON '-' + t2.TRAILS + '-' LIKE '%-' + t1.TRAILS + '-%'
WHERE t2.ACOUNTCODE = 10201
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -