Solved

number of transactions per day per shipper

Posted on 2014-02-07
2
302 Views
Last Modified: 2014-02-07
Hi Experts,
I am trying to determine how many transaction records each of our shippers had per day last year. The following query correctly returns the total number of transactions per day.

SELECT CONVERT(CHAR(10), A.DATETIME_ENDED,101), COUNT(*) AS TOTAL_NUM
FROM MYDB.XACSTAT AS A
WHERE
A.CANCELLED = 0 AND A.XACTYPE = 3 AND YEAR(A.DATETIME_ENDED) = 2013
GROUP BY CONVERT(CHAR(10), A.DATETIME_ENDED,101);

I would like the query to return additional columns for the number of transactions for each 0day where A.SHIPPER = 1095 AND A.SHIPPER = 2969. (There are other shippers besides these two.)  

For example, the first few rows of output data might look something like this...
DATE          TOTAL_NUM       NUM_1095      NUM_2969
-------          ------------------      ----------------      ---------------
1/1/2013             20                        5                    10
1/2/2013             25                      25                      0
1/3/2013             30                       0                       5
1/4/2013             40                       0                       0


Again, I would like to add two columns to my existing query - one for the number of transactions per day for shipper 1095 (NUM_1095) and another for the number of transactions per day for shipper 2969 (NUM_2969).

Any help would be appreciated.
0
Comment
Question by:munequito
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 16

Accepted Solution

by:
Surendra Nath earned 500 total points
ID: 39842344
try this

SELECT CONVERT(CHAR(10), A.DATETIME_ENDED,101), COUNT(*) AS TOTAL_NUM
,COUNT(CASE A.SHIPPER WHEN 1095 THEN 1 ELSE 0 END) AS NUM_1095
,COUNT(CASE A.SHIPPER WHEN 2969 THEN 1 ELSE 0 END) AS NUM_2969
FROM MYDB.XACSTAT AS A 
WHERE 
A.CANCELLED = 0 AND A.XACTYPE = 3 AND YEAR(A.DATETIME_ENDED) = 2013 
GROUP BY CONVERT(CHAR(10), A.DATETIME_ENDED,101);

Open in new window

0
 

Author Closing Comment

by:munequito
ID: 39842361
Surendra,
Your query was returning the same value in each field. I simply changed "count" to "sum" - which you probably intended - and it now returns the correct values I was looking for.

Thanks so much for your solution.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Load Fact table in SQL Server SSIS package 14 45
Any benefit to adding a Clustered index here? 4 39
Do not display comma when no last name 8 48
Report 8 27
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

738 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