select case totals

Posted on 2007-08-02
Medium Priority
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

imran_fast earned 2000 total points
ID: 19633550
Whats wrong with the above code?

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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.
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …

807 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