sql server - SQL grouping not working -


i using ms sql server 2012

i have query uses subquery create column shows summed percent of assets. need summed column group portfoliobasecode shown below.

i have tried group , partition without success. group result portfolio codes correctly group summedpct still total of portfolios , not subtotaling want.

cashpct

with partition following error. can use top 1 not give desired result.

error

msg 512, level 16, state 1, line 17 subquery returned more 1 value. not permitted when subquery follows =, !=, <, <= , >, >= or when subquery used expression. 

error

using top 1

top1

it may placing group or partition on in wrong place in query. need way correctly group column summedpct.

here query: https://dl.dropboxusercontent.com/u/29851290/cashpercent.sql

here result set , desired result.

cashpct

the problem actual result is taking sum total of percentassets , placing them in summedpct.

the result want these percent of assets grouped portfoliobasecode. note in desired result set summedpct of chambetr 2.66 -457.50+460.18

you cannot use "inline" query because returns 1 row each partition. so, need "join" think. perhaps work:

 use apxfirm --1. establish apx user session declare @sessionguid nvarchar(70) exec apxuser.psessioninfosetguid @sessionguid  --2. execute query against appraisal accounting function declare @reportdata varbinary(max) exec apxuser.pappraisal  -- required parameters. there may other optional parameters. @reportdata = @reportdata out, @portfolios = '@test_group', @date = '10/02/2013'  --3. select columns  select --appraisal columns a.marketvalue, a.percentassets, --security columns s.securitysymbol, s.securitytypecode,  -- portfolio base columns b.portfoliobasecode, b.reportheading1, bb.summedpct  --4. join appraisal additional views apxuser.fappraisal (@reportdata) left join apxuser.vportfoliobasesettingex b on b.portfoliobaseid = a.portfoliobaseid left join apxuser.vsecurityvariant s on s.securityid = a.securityid   left join(    select portfoliobasecode        , sum(percentassets) summedpct    apxuser.fappraisal (@reportdata) aa    left join apxuser.vportfoliobasesettingex b on b.portfoliobaseid = aa.portfoliobaseid left join apxuser.vsecurityvariant s on s.securityid = aa.securityid     s.sectypecode 'ca%'     , s.sectypecode = aa.sectypecode    , s.isshort = aa.isshortposition    group portfoliobasecode, securitytypecode    ) bb on b.portfoliobasecode = bb.portfoliobasecode s.sectypecode 'ca%' , s.sectypecode = a.sectypecode , s.isshort = a.isshortposition , summedpct >= @summedpct 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -

php - Accessing static methods using newly created $obj or using class Name -