select case totals

Posted on 2007-08-02
Last Modified: 2010-03-19
Hi, when using a select case query how can I get a total row calculation of columns.  Here is an example of the code I am using.
select a.item1,
      sum (case
when a.item1 in ('value1', 'value2', 'value3')
      then 1
      else 0
            end) as 'abc',
      sum (case
when a.item1 in ('value1', 'value2', 'value3')
      then 1
      else 0
      end) as 'def',
from tbl1 as a join tbl2 as b
on a.item1 = b.item1 where datepart(dd, getdate()) = datepart(dd, datefield1)
and b.item2 is not null and reasoncode IN ( 'g', ' h',  'i',  'j' )
group by a.item1
Question by:marcus72
    1 Comment
    LVL 28

    Accepted Solution

    Whats wrong with the above code?

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    When writing XML code a very difficult part is when we like to remove all the elements or attributes from the XML that have no data. I would like to share a set of recursive MSSQL stored procedures that I have made to remove those elements from …
    This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now