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 2012 Forums
 Transact-SQL (2012)
 sum value of a field
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

rjhe22
Constraint Violating Yak Guru

283 Posts

Posted - 01/21/2014 :  11:38:23  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

USA
1834 Posts

Posted - 01/21/2014 :  19:19:41  Show Profile  Reply with Quote
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

Edited by - Bustaz Kool on 01/21/2014 19:21:30
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52326 Posts

Posted - 01/22/2014 :  06:57:41  Show Profile  Reply with Quote

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



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
  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