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 2005 Forums
 Transact-SQL (2005)
 Problem in Query

Author  Topic 

abhit_kumar
Posting Yak Master

147 Posts

Posted - 2012-04-11 : 01:40:18
Dear All Experts,

As per below snaps i want to achieve final amount (last column), based on the condition of number of occurence of SO No against Inv No. If SO No have two inv no then SO amt divided by half, if it comes three times then Final amt divided by three times and distributed equally against Inv No.



Please guide.

Regards,
AKM

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2012-04-11 : 07:38:54
Careful with data types here, so that the pieces ad back to the whole

UPDATE T1
SET FinalAmt = T1.SoAmt/ T2.Recs

FROM yourTable T1
INNER JOIN

(
select SoNo,SoAmt,COUNT(*) as Recs
from yourTable
group by SoNo,SoAmt
) T2

ON T1.SoNo = T2.SoNo


Jim

Everyday I learn something that somebody else already knew
Go to Top of Page
   

- Advertisement -