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.
Author |
Topic |
Naveed88
Starting Member
19 Posts |
Posted - 2009-04-13 : 06:54:59
|
Hi all,I want to Update few records in a table with another table's valuesby Inner join Table1ID Name Amount1 AAA 1002 BBB 2003 CCC 3004 DDD 400and Another one isTable2ID Discount1 502 604 80what i want to update all Table1.Amountby Table2like Subtract all discount from amounts in Table1 which are Exist inTable2-----also i tried this UPDATE DISTINCTROW table1 t1INNER JOIN table2 t2 ON t1.code=t2.codeSET t1.name=T2.name where <condition>---UPDATE [Table1] ; SET [Table1.SomeField] = [Table2.SomeField] ; FROM [Table1] INNER JOIN [Table2] ; ON [Table1.key]= [Table2.key]but it does not work!!!(¨`·.·´¨) Always`·.¸(¨`·.·´¨) Keep(¨`·.·´¨)¸.·´ Smiling!`·.¸.·´ & ProgrammingRegards...."Deevan" [Naveed Anjum]Web Developer,9867374437-Mumbai.4 |
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2009-04-13 : 07:08:31
|
is this u wantdeclare @Table1 table(ID int, Name varchar(12), Amount decimal(18,2))insert into @table1 select 1, 'AAA', 100 union all select2, 'BBB', 200 union all select3, 'CCC', 300 union all select4, 'DDD', 400declare @Table2 table(ID int, Discount decimal(18,2))insert into @table2 select1, 50 union all select2, 60 union all select4, 80select * from @table1select * from @table2update tset amount = amount-discountfrom @table1 tinner join @table2 s on s.id = t.idselect * from @table1 |
|
|
Naveed88
Starting Member
19 Posts |
Posted - 2009-04-13 : 07:21:44
|
Thanks that's itProblem Solved (¨`·.·´¨) Always`·.¸(¨`·.·´¨) Keep(¨`·.·´¨)¸.·´ Smiling!`·.¸.·´ & ProgrammingRegards...."Deevan" [Naveed Anjum]Web Developer,9867374437-Mumbai.4 |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2009-04-13 : 07:24:18
|
quote: Originally posted by Naveed88 Thanks that's itProblem Solved (¨`·.·´¨) Always`·.¸(¨`·.·´¨) Keep(¨`·.·´¨)¸.·´ Smiling!`·.¸.·´ & ProgrammingRegards...."Deevan" [Naveed Anjum]Web Developer,9867374437-Mumbai.4
welcome |
|
|
|
|
|
|
|