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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 UPDATING ROWS USING VALUE GET FROM TABLE
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Crz_Gordo
Starting Member

Philippines
1 Posts

Posted - 11/08/2013 :  03:23:22  Show Profile  Reply with Quote
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

India
52326 Posts

Posted - 11/08/2013 :  04:30:27  Show Profile  Reply with Quote

UPDATE t1
SET AMOUNT = 100.00
FROM Table t1
INNER JOIN Table t2
ON '-' + t2.TRAILS + '-' LIKE '%-' + t1.TRAILS  + '-%'
WHERE t2.ACOUNTCODE = 10201


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.07 seconds. Powered By: Snitz Forums 2000