SQL Server Forums
Profile | Register | 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
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

rjhe22
Constraint Violating Yak Guru

254 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
1721 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
52317 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  
 New 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.44 seconds. Powered By: Snitz Forums 2000