What's the best way to create sub-totals & grand-total in SQL2008 R2 (and beyond)?

What is the easiest way to get sub totals and a grand total on data that is being grouped?  It looks like RollUp might work, but it's being depreciated.
My query is:
SELECT
COMPANY
,INVSTR_CD
,STATE_C
,SUM(CO_SHARE_TOTBAL) as CO_SHARE_TOTBAL
FROM #ASSET AS A
WHERE A.D_GETIT = 'Y'
GROUP BY COMPANY, STATE_C, INVSTR_CD
ORDER BY COMPANY, INVSTR_CD, STATE_C
I need to provide a sub-total of the SUM'd field (SUM(CO_SHARE_TOTBAL) as CO_SHARE_TOTBAL), at the change of the COMPANY field.
Then a Grand Total of all the SUM'd fields (SUM(CO_SHARE_TOTBAL).
Thanks in advance!!
-Al H

If you post DDL of your table (only relevant columns) and some data and desired output, I may try to reproduce it. Did you check Jacob's blog post and the very last query? It does take a few trials before getting this correct. 
Naomi,
I did try the last query on Jacob's post.  I couldn't get the first column to populate.
Thanks for the offer of help.
DML is:
Create Table #ASSET2 (
[COMPANY] [varchar] (5) NULL
,[INVSTR_CD] [varchar](5) NULL
,[STATE_C] [char](2) NULL
,[SHARE_TOTBAL] [decimal] (15,2) NULL)
Data is:
Insert into #ASSET2 VALUES ('00000','099 ','FL','115226.77')
Insert into #ASSET2 VALUES ('22222','030 ','CA','309899.43')
Insert into #ASSET2 VALUES ('00000','010 ','CA','524296.89')
Insert into #ASSET2 VALUES ('00000','099 ','IL','51699.70')
Insert into #ASSET2 VALUES ('00000','789 ','PA','90856.04')
Insert into #ASSET2 VALUES ('22222','010 ','CA','66951.33')
Insert into #ASSET2 VALUES ('00000','099 ','CA','310046.03')
Insert into #ASSET2 VALUES ('00000','010 ','AZ','178062.08')
Insert into #ASSET2 VALUES ('00000','099 ','NY','278489.10')
Desired results would be the following:
COMPANY INVSTR_CD STATE_C SHARE_TOTBAL
00000 010 AZ 178062.08
00000 010 CA 524296.89
00000 099 CA 310046.03
00000 099 FL 115226.77
00000 099 IL 51699.70
00000 099 NY 278489.10
00000 789 PA 90856.04
TOTAL COMPANY 00000 1548676.61
22222 010 CA 66951.33
22222 030 CA 309899.43
TOTAL COMPANY 22222 376850.76
GRAND TOTAL 1925527.37
-Al H

Similar Messages

  • What is the best way to create business documents in CRM

    Hi All,
    What is the best way to create business documents like contract, sales order, debit memo etc in CRM ? Unlike R3 we can't use our good old BDC with recording. Moreover for most of them although there are Business Object but no BAPI to creation so what is the way ? I found in SDN there are two MAGIC Function module CRMXIF_ORDER_SAVE. Do I need to that alawys ?
    Is it nees to via IDoc and cannot be done just by calling from ABAP program ? The input parameter of the FM is a complex deep structure.
    Please help.

    Ashim,
    Try looking at the program:
    CRM_TEST_ORDER_MAINTAIN
    I think that should help you figure out the parameters.
    Good luck,
    Stephen

  • What is the best way to create a database schema from XML

    What is the best way to create a database schema from XML?
    i have  a complex XML file that I want to create a database from and consistently import new XML files of the same schema type. Currently I have started off by mapping the XSD into Excel and using Mysql for Excel to push into MySQL.
    There must be a more .net microsoft solution for this but I cannot locate the topic and tools by searching. What are the best tools and way to manage this?
    Taking my C# further

    Hi Saythj,
    When mentioning "a database schema from XML", do you mean the
    XML Schema Collections? If that is what you mean, when trying to import XML files of the same schema type, you may take the below approach.
    Create an XML Schema Collection basing on your complex XML, you can find
    many generating tools online to do that.
    Create a Table with the above created schema typed XML column as below.
    CREATE TABLE youTable( Col1 int, Col2 xml (yourXMLSchemaCollection))
    Load your XML files and try to insert the xml content into the table above from C# or some other approaches. The XMLs that can't pass the validation fail inserting into that table.
    If you have any question, feel free to let me know.
    Eric Zhang
    TechNet Community Support

  • What is the best way to create CRUD datagrids

    What is the best way to create CRUD datagrids that tell CF
    components to update sql tables. I find that I'm having to vreate
    all these columns with custom properites and its a bit of a chore:
    <mx:DataGridColumn id = "NatWest" dataField="NatWest"
    headerText="NatWest" editable="false"
    wordWrap="true"
    textAlign="right"
    headerStyleName="centered"
    labelFunction="price_labelFuncNatWest"
    sortCompareFunction="price_sortCompareFunc">
    I don't really want to use any wizards as I want control over
    my code.

    Hi Saythj,
    When mentioning "a database schema from XML", do you mean the
    XML Schema Collections? If that is what you mean, when trying to import XML files of the same schema type, you may take the below approach.
    Create an XML Schema Collection basing on your complex XML, you can find
    many generating tools online to do that.
    Create a Table with the above created schema typed XML column as below.
    CREATE TABLE youTable( Col1 int, Col2 xml (yourXMLSchemaCollection))
    Load your XML files and try to insert the xml content into the table above from C# or some other approaches. The XMLs that can't pass the validation fail inserting into that table.
    If you have any question, feel free to let me know.
    Eric Zhang
    TechNet Community Support

  • What is the best way to create a read more/collapse text box on the homepage of a site?

    What is the best way to create a read more/collapse text box on the homepage of a site?

    I figured this out by using a lightbox. I set the trigger at the top of the box, hid all initially and added a close button. In the box that would have linked to the first thumbnail for the lightbox, I added a text box that said "read more"

  • What is the best way to create shared variable for multiple PXI(Real-Time) to GUI PC?

    What is the best way to create shared variable for multiple Real time (PXI) to GUI PC? I have 16 Nos of PXI system in network and 1 nos of GUI PC. I want to send command to all the PXI system with using single variable from GUI PC(Like Start Data acquisition, Stop data Acquisition) and I also want data from each PXI system to GUI PC display purpose. Can anybody suggest me best performance system configuration. Where to create variable?(Host PC or at  individual PXI system).

    Dear Ravens,
    I want to control real-time application from host(Command from GUI PC to PXI).Host PC should have access to all 16 sets PXI's variable. During communication failure with PXI, Host will stop data display for particular station.
    Ravens Fan wrote:
    Either.  For the best performance, you need to determine what that means.  Is it more important for each PXI machine to have access to the shared variable, or for the host PC to have access to all 16 sets of variables?  If you have slowdown or issue with the network communication, what kinds of problems would it cause for each machine?
    You want to located the shared variable library on whatever machine is more critical.  That is probably each PXI machine, but only you know your application.
    Ravens Fan wrote:
    Either.  For the best performance, you need to determine what that means.  Is it more important for each PXI machine to have access to the shared variable, or for the host PC to have access to all 16 sets of variables?  If you have slowdown or issue with the network communication, what kinds of problems would it cause for each machine?
    You want to located the shared variable library on whatever machine is more critical.  That is probably each PXI machine, but only you know your application.

  • What is the best way to create E-Flyers and insert to Microsoft Outlook??

    What is the best way to create E-Flyers and insert to Microsoft Outlook??

    http://kb.mailchimp.com/article/how-to-code-html-emails
    Once created, the HTML document cab be placed in the Stationery folder.
    On a PC it's here.
    "C:\Program Files\Common Files\Microsoft Shared\Stationery"

  • What is the best way to create Aperture book from Pages '09 document?

    What is the best way to create Aperture book from Pages '09 document?

    There is no way to import pages documents to Aperture and convert them to an Aperture book. Aperture books can only be created by manually adding images and text to the pages of a book, and using the layout of the predefined templates.
    The best you could do, would be to print your pages document to pdf and import the resulting pdf file into Aperture as a new project. This will create one image for each page. Then select the page images all at once and  create a new book. Select a theme with fullsize page images, like "picture Book", and then add the images of the pages to the empty pages of the book.
    But probably would you get a much better quality and layout, when you recreate your pages document in Aperture, by starting with an empty book and copying and pasting the text from your Pages document. But don't paste the photos from the document - try to use the originals of those photos.

  • What is the best way to create space for a Yosemite download?

    What are the best ways to create space for the download of Yosemite.  I can't install it as I don't have enough space.

    Did you empty Trash?  Very important!
    How much space do you have available?  Click in the HDD icon on the desktop, COMMAND+I.
    Also try a Safe Boot:
    http://support.apple.com/kb/HT1564?viewlocale=en_US
    That will temporarily create some additional space.
    Ciao.

  • Dw, css, and a template, what is the best way to create a 20 page website with a different header in each page?

    dw, css, and a template, what is the best way to create a 20
    page website with different header content on each page? i am
    trying to insert a specific image and background color for each
    header on every page. what is the easiest or best way to do this?
    thanks, bryan

    "mediastream13" <[email protected]> wrote in
    message
    news:f47bes$9om$[email protected]..
    > ok, murray, here is the site.
    http://www.helphotline.org
    > in I.E. 6 i can't see the background color behind the
    header images,
    I'm seeing a hot pink background (which is my browser default
    - so that I do
    remember to declare a background color). You need to add:
    body { background-color: white;} to your stylesheet, or into
    the imbedded
    styles on your page.
    In Firefox, the very top black section, #headertop is hidden
    behind the
    header image.
    > background of the date/time isn't stretching the full
    length of the
    > screen, and
    > the margins aren't working in the main content area. how
    can i put a
    > background
    > color behind the header images?
    I can see the header image stretching right across the page..
    so not sure
    what color is missing there.
    > is there anyway to download i.e. six on my computer if i
    already have
    > i.e.7? i
    > just want to be able to preview the site before i upload
    the changes. it
    > seems
    > everything works in i.e. 7.
    Yes, I used this and it works really well.
    http://tredosoft.com/Multiple_IE
    Nadia
    Adobe® Community Expert : Dreamweaver
    CSS Templates |Tutorials |SEO Articles
    http://www.DreamweaverResources.com
    ~ Customisation Service Available ~
    http://www.csstemplates.com.au

  • What is the best way to create a Flash site

    Hello Everyone,
    I am realtively new to flash. I created the splash page of
    our site in flash but 1st off it takes to long to load as it is.
    But I would like to create the entire site in Flash. What is the
    best way to create a Flash site, and are there tutorials out there
    or any really good books, resources, or online classes to learn
    Flash well. I understand the basic of flash and have created
    banners, and other flash materials.
    Can anyone help?

    For me, as a noob, It's all about creative problem solving.
    For lots of stuff, there's no right or wrong solution, but you have
    to figure things out on your own. I, too, have built sites from the
    ground up, and then rebuilt them even better. It's the only way to
    really learn it well. Books, online forums, help docs all sort of
    help, but it all comes down to how innovative you can be with
    integrating them all into a site that is completely yours.
    This might save you loads of headaches: avoid using scenes,
    unless you are doing only animation. Keep each of your 'pages' on
    their own keyframe, and use 'gotoAndStop' to navigate through them.
    This is perhaps the easiest way to create a website quickly.
    P

  • Hi all! What is the best way to create the correct space for baseball jersey names and numbers? along with making sure they are the right size for large printing.

    What is the best way to create the correct space for baseball jersey names and numbers? along with making sure they are the right size for large printing.

    Buying more hard drive space is a very valid option, here.  Editing takes up lots of room, you should never discount the idea of adding more when you need it.
    Another possibility is exporting to MXF OP1a using the AVC-I codec.  It's not lossless, but it is Master quality.  Plus the file size is a LOT smaller, so it may suit your needs.

  • What is the best way to create 10000 users in ECC system

    Dear all,
    what is the best way to create 10,000 users in ECC 6 system.
    As of my knowledge we can create with SECATT, but I don't know the procedure to use this.
    please guide me...
    Regards,
    Raaja

    Hi Raaja,
    If you search in SDN or on google for eCATT tutorial, you will get all the info you need to learn to create them.
    For 10000 users I would suggest the following
    1. eCATT to create user ID's (include all the info like passwords, user groups in here).
    2. eCATT to make the role assignment.  Use SU10 to record the assignment to the users you created with the first script as it gives you more flexibility
    If you have the data you need then you should be able to run both steps in 1 work day (dependent on system performance).
    Edited by: Alex Ayers on Jan 25, 2009 11:16 AM

  • What's the best way to create a login page in muse?

    Hi.
    Busy exploring muse I came across another problem:
    What’s the best way to create a login page in muse?
    I want to create 1 page on a site with access for people with login details only.
    Sorry for beeing a newbie
    Dutch greets
    Toin Corten

    Hi Toin,
    Never need to apologize for being a newbie...we all were at one point or another. 
    I am going to move this question to the main Muse forum where you'll have a much better chance of getting a response.  This particular forum is for questions around our Muse getting started project.
    You may also want to check this thread out: http://forums.adobe.com/thread/1004543.
    Thank you,
    Ed Sullivan

  • What's the best way to create/stitch panorama photos with Aperture?

    What's the best way to create/stitch panorama photos with Aperture?
    Many thanks
    Best

    There is no way to do this with Aperture. This thread
    https://discussions.apple.com/thread/3714693?start=0&tstart=0
    has some suggestions.

Maybe you are looking for

  • Adding second VGA monitor

    Hi - I recently purchased the 20" intel imac. When I purchased it I also purchased the mini DVI adapter to connect to a television - that works great. I also wanted the option of setting up a second monitor with my computer. I have two older VGA moni

  • Change Document Numbering for Contracts

    Experts, I have a client who wants to create a new Document Series for the Contracts and Service Calls in SBO. I do not see these documents available in the Document Numbering screen. Is this possible? Thanks, Marli

  • Single Value in F4

    Hi SDN's, Can u tell me how to get single field value in F4 help. I need to get single F4 value as USD as currency field value instead of getting all other field values for Currency key in ME51N Transaction .( As per client requirement) Screen field

  • Have a Panasonic PV-GS9 mini camera (tape)-newer computer with 10.7.5 iMovie does not recognize. Previous computer with 10.4.11 worked?

            Mar 28, 2013 11:36 AM    Have read a couple of "how to" downloads (iMovie'11:import video), followed the instructions with no success. Am using cable with firewire connector. Any ideas? thanks, Bevo 36 MacBook Pro, Mac OS X (10.7.5)

  • My total number of posts has been cut drastically.

    Hello I enjoy posting to the discussions here. sometimes, I'll open the discussions on my Powerbook while watching TV, and I'll answer a few questions while I watch. It's fun. One of the nifty little incentives was waiting until I got to 600 posts so