Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8541353
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:48:45+00:00 2026-06-11T11:48:45+00:00

I currently have a script below which aggregates some data using rollup: SELECT CASE

  • 0

I currently have a script below which aggregates some data using rollup:

SELECT 
        CASE 
            WHEN GROUPING(Custodian) = 1 
                THEN 'Grand Total'
            WHEN GROUPING(PortfolioID) = 1
                THEN Custodian+''+'Total'
            ELSE Custodian

        END AS Custodian

    ,   PortfolioID
    ,   PortfolioBaseCCY
    ,   [Date]
    ,   SUM(AmountTotalBaseEquiv) AS AmountTotalBaseEquiv
    ,   ExchangeRate
    ,   AmountTotalBaseEquivUSD
    ,   PortfolioNAVUSD
    ,   SUM(TotalCashPctNAV) AS TotalCashPctNAV 

FROM @ResultSet
WHERE TotalCashPctNAV > 5
GROUP BY Custodian
    ,   PortfolioID
    ,   PortfolioBaseCCY
    ,   [Date]
    ,   AmountTotalBaseEquiv
    ,   ExchangeRate
    ,   AmountTotalBaseEquivUSD
    ,   PortfolioNAVUSD 
    ,   TotalCashPctNAV WITH ROLLUP

HAVING GROUPING_ID(Custodian
    ,   PortfolioID
    ,   PortfolioBaseCCY
    ,   [Date]
    ,   AmountTotalBaseEquiv
    ,   ExchangeRate
    ,   AmountTotalBaseEquivUSD
    ,   PortfolioNAVUSD 
    ,   TotalCashPctNAV) IN (1,255,511)

ORDER BY CASE WHEN GROUPING(Custodian) = 1 THEN 2 ELSE 1 END, Custodian, TotalCashPctNAV DESC, PortfolioID

This returns data like as an example:

Custodian   PortfolioID PortfolioBaseCCY Date         AmountTotalBaseEquiv  ExchangeRate    AmountTotalBaseEquivUSD PortfolioNAVUSD TotalCashPctNAV
XXXX        TEST        USD              11/09/2012   85708860.21           1               85708860.21             370253861.3     23.15
XXXX  Total NULL        NULL             NULL         85708860.21           NULL            NULL                    NULL            23.15
ZZZZ        TEST1       GBP              11/09/2012   48427.91              0.6225          77795.84                77795.84        100
ZZZZ        TEST2       GBP              11/09/2012   7772.61               0.6225          12486.12                12486.12        100
ZZZZ        TEST3       USD              11/09/2012   1832627.81            1               1832627.81              17343500.68     10.56
ZZZZ  Total NULL        NULL             NULL         1888828.33            NULL            NULL                    NULL            210.56
Grand Total NULL        NULL             NULL         310273031.4           NULL            NULL                    NULL            1051.71

What i would like is for the NULLS to become ” so that only the Total label and the two summed totals are the only bits of data on that particular line, is this possible?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T11:48:46+00:00Added an answer on June 11, 2026 at 11:48 am

    If you are okay with NULL values appearing as empty strings in both data rows and total rows, you can convert all of the non-string columns to strings and use COALESCE (or ISNULL) like:

    SELECT  
            CASE  
                WHEN GROUPING(Custodian) = 1  
                    THEN 'Grand Total' 
                WHEN GROUPING(PortfolioID) = 1 
                    THEN Custodian+' '+'Total' 
                ELSE Custodian 
    
            END AS Custodian 
    
        ,   COALESCE(PortfolioID,'') AS PortfolioID
        ,   COALESCE(PortfolioBaseCCY,'') AS  PortfolioBaseCCY
        ,   COALESCE(CONVERT(char(10),[Date],101),'') AS [Date]
        ,   SUM(AmountTotalBaseEquiv) AS AmountTotalBaseEquiv 
        ,   COALESCE(CONVERT(char(10),ExchangeRate),'') AS ExchangeRate
        ,   COALESCE(CONVERT(char(20),AmountTotalBaseEquivUSD),'') AS AmountTotalBaseEquivUSD
        ,   COALESCE(CONVERT(char(20),PortfolioNAVUSD),'') AS PortfolioNAVUSD
        ,   SUM(TotalCashPctNAV) AS TotalCashPctNAV
    
    FROM @ResultSet 
    WHERE TotalCashPctNAV > 5 
    GROUP BY Custodian 
        ,   PortfolioID 
        ,   PortfolioBaseCCY 
        ,   [Date] 
        ,   AmountTotalBaseEquiv 
        ,   ExchangeRate 
        ,   AmountTotalBaseEquivUSD 
        ,   PortfolioNAVUSD  
        ,   TotalCashPctNAV WITH ROLLUP 
    
    HAVING GROUPING_ID(Custodian 
        ,   PortfolioID 
        ,   PortfolioBaseCCY 
        ,   [Date] 
        ,   AmountTotalBaseEquiv 
        ,   ExchangeRate 
        ,   AmountTotalBaseEquivUSD 
        ,   PortfolioNAVUSD  
        ,   TotalCashPctNAV) IN (1,255,511) 
    
    ORDER BY CASE WHEN GROUPING(Custodian) = 1 THEN 2 ELSE 1 END, Custodian, TotalCashPctNAV 
    

    Otherwise, you can use a case expression, as you did with Custodian, to determine which rows are totals. For example:

    CASE WHEN GROUPING(Custodian) + GROUPING(PortfolioId) > 0 THEN '' 
         ELSE PortfolioID END AS PortfolioID
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have a script that deletes old log files and then takes any
I currently have a script which allows me to output the list of files
I currently have a ajax script that dynamically builds two select boxes enabled with
Currently Im have the following script which checks to see if a checkbox value
Currently I have a bash script which runs the find command, like so: find
I currently have a Perl CGI script that parses incoming XML requests using XML::Simple
Currently I have a JQuery script in place http://jsfiddle.net/gaby/zzj7E/5/ which handles the requirement that
Updated below: I have a script which has a function I made that calculates
I have currently a DNS Reverse lookup script which works however there is a
I currently have a script that scrapes proxies off websites, but I'm just wondering

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.