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 2012 Forums
 Transact-SQL (2012)
 sum value of a field

Author  Topic 

rjhe22
Constraint Violating Yak Guru

283 Posts

Posted - 2014-01-21 : 11:38:23
hi have this code
Update dbo.SSCIREWorkingDataloadFile
set LocalCrossTrade = BASE_MKT_VAL
where INV_SECTYPE_COD = '61'
or INV_SECTYPE_COD = '62'
or INV_SECTYPE_COD = '63'
or INV_SECTYPE_COD = '64'
or INV_SECTYPE_COD = '65'
or INV_SECTYPE_COD = '71'
or INV_SECTYPE_COD = '72'
or INV_SECTYPE_COD = '73'
or INV_SECTYPE_COD = '74'
or INV_SECTYPE_COD = '75'

where it say LocalCrossTrade = BASE_MKT_VAL i want to sum the BASE_MKT_VAL fields and set that equal to the LocalCrossTrade

whats the best way to do this

Bustaz Kool
Master Smack Fu Yak Hacker

1834 Posts

Posted - 2014-01-21 : 19:19:41
Can I ask you to elaborate a little? You want to sum BASE_MKT_VAL over the entire table? Only where INV_SECTYPE_CODE = '61', '62', etc.? Grouped by some other column? Perhaps some sample data and expected outputs would shed some light.

=================================================
A man is not old until regrets take the place of dreams. - John Barrymore
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2014-01-22 : 06:57:41
[code]
Update t
set LocalCrossTrade = Total_BASE_MKT_VAL
FROM
(
SELECT *,SUM(BASE_MKT_VAL) OVER (PARTITION BY <somefieldhere>) AS Total_BASE_MKT_VAL
FROM dbo.SSCIREWorkingDataloadFile
where INV_SECTYPE_COD IN ('61','62','63','64','65','71','72','73','74','75')
)t

[/code]

Please fill part in blue by field(s) based on which you want to sum the BASE_MKT_VAL field


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

- Advertisement -