Author |
Topic |
bilencekic
Posting Yak Master
121 Posts |
Posted - 2006-09-01 : 10:26:06
|
tbl_MoneysID-----Money1-----10002-----500tbl_debtssID----debts1-----1002-----240i want a result liketbl_MoneysID-----Money1-----9002-----260i tried some queries but didint workMS BLESS US |
|
sanjnep
Posting Yak Master
191 Posts |
Posted - 2006-09-01 : 10:35:49
|
update tbl_Money set Money = a.Money-b.Money from tbl_Money as a inner join tbl_debts as b on a.sID = b.sID |
 |
|
bilencekic
Posting Yak Master
121 Posts |
Posted - 2006-09-01 : 10:39:35
|
update queryMS BLESS US |
 |
|
bilencekic
Posting Yak Master
121 Posts |
Posted - 2006-09-02 : 05:01:57
|
so ??i need an update querynot a selectMS BLESS US |
 |
|
chiragkhabaria
Master Smack Fu Yak Hacker
1907 Posts |
Posted - 2006-09-02 : 07:29:37
|
quote: so ??i need an update querynot a select
I dont see any where select query.. .. try the query which is posted by sanjnep, it should be fine..Chirag |
 |
|
tishri
Yak Posting Veteran
95 Posts |
Posted - 2006-09-02 : 08:29:53
|
update m set m.[money] = m.[money] - d.[money]from tbl_money m inner join tbl_debts d on m.sid=d.siddo this...TCC |
 |
|
bilencekic
Posting Yak Master
121 Posts |
Posted - 2006-09-02 : 09:51:30
|
lol sorry yep right i though that you can use inner join in updateMS BLESS US |
 |
|
shaggy
Posting Yak Master
248 Posts |
Posted - 2006-09-04 : 02:38:57
|
update tbl_Money set Money = a.Money,a.1=b.1,a.2=b.2from tbl_Money a, tbl_debts bwhere a.timestamp = '' (that u can see in select query)and b.timestamp = '' (that u can see in select query) |
 |
|
chiragkhabaria
Master Smack Fu Yak Hacker
1907 Posts |
Posted - 2006-09-04 : 02:45:26
|
quote: Originally posted by shaggy update tbl_Money set Money = a.Money,a.1=b.1,a.2=b.2from tbl_Money a, tbl_debts bwhere a.timestamp = '' (that u can see in select query)and b.timestamp = '' (that u can see in select query)
I dont think this, what bilencekic requires..Chirag |
 |
|
bilencekic
Posting Yak Master
121 Posts |
Posted - 2006-09-14 : 06:15:45
|
damn it doenst work.how to run this update ?it updates all columns with the same value.update d set Kota=Kota-(select sum(t2.DailyValue) from SKB t2 inner join tbl_Kotalar don d.UserID= t2.UserID )from tbl_Kotalar d inner join SKB t2 ont2.USerID = d.UserID the sum function makes it difficultMS BLESS US |
 |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-09-14 : 06:20:17
|
[code]update d set Kota = d.Kota - t2.DailyValuefrom tbl_Kotalar d inner join SKB t2 on t2.UserID = d.UserID[/code]Do you have multiple record in SKB table per UserID ? KH |
 |
|
chiragkhabaria
Master Smack Fu Yak Hacker
1907 Posts |
Posted - 2006-09-14 : 06:23:58
|
update d set Kota=Kota-(select sum(t2.DailyValue) from SKB t2 inner join tbl_Kotalar don d.UserID= t2.UserIDGroup by UserID)from tbl_Kotalar d inner join SKB t2 ont2.USerID = d.UserID Chirag |
 |
|
bilencekic
Posting Yak Master
121 Posts |
Posted - 2006-09-14 : 07:02:11
|
yes i have multiple records per USerID.UserID--WordID--DailyValue1--1--1001--2--1501--3--2002--1--90..so user 1 has total dailyvalue 450.and update will get 450 then update the user1's section in tbl_Kotalar. tbl_kotalar doenst have nultiple recrods per user.tbl_KotalarUserID--Kota1-6002-500after update it will be like this.1-1502-410MS BLESS US |
 |
|
bilencekic
Posting Yak Master
121 Posts |
Posted - 2006-09-14 : 07:04:36
|
chirag:Msg 512, Level 16, State 1, Line 1Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.The statement has been terminated.group by returns more then 1 result yep that is right. but it doenst update :(MS BLESS US |
 |
|
bilencekic
Posting Yak Master
121 Posts |
Posted - 2006-09-14 : 08:01:43
|
ok i have fixed it with a temp tableMS BLESS US |
 |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-09-14 : 10:23:02
|
[code]update d set Kota = d.Kota - t2.Total_DailyValuefrom tbl_Kotalar d inner join ( select UserID, sum(DailyValue) as Total_DailyValue from SKB group by UserID ) t2on t2.UserID = d.UserID[/code] KH |
 |
|
|