473,387 Members | 1,590 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Query Help

When I run this query it outputs the dates from the 14th of Nov to the 31st (well up to the last date in the db which atm is the 6th of dec) twice for each date because we have two order status values for each day.. Which is what I would like it to do..

However I would like to make it so if a particular row does not have a value <> 0 in any of the Orders fields that row is not displayed hence only displaying days/orderstatuses with actual orders and not days with 0's in all the COUNT(CASE WHEN discountoffercode = '##' THEN 1 END) Fields... I have tried so many things and I just cant figure out how to do this


Expand|Select|Wrap|Line Numbers
  1. SELECT     ReceivedDate, OrderStatus, COUNT(CASE WHEN discountoffercode = '88' THEN 1 END) AS OrdersCisco, 
  2.                       SUM(CASE WHEN discountoffercode = '88' THEN ordertotal END) AS SalesCisco, COUNT(CASE WHEN discountoffercode = '89' THEN 1 END) 
  3.                       AS OrdersTDS, SUM(CASE WHEN discountoffercode = '89' THEN ordertotal END) AS SalesTDS, 
  4.                       COUNT(CASE WHEN discountoffercode = '90' THEN 1 END) AS OrdersBerbeeCDW, SUM(CASE WHEN discountoffercode = '90' THEN ordertotal END) 
  5.                       AS SalesBerbeeCDW, COUNT(CASE WHEN discountoffercode = '91' THEN 1 END) AS OrdersQuadGfx, 
  6.                       SUM(CASE WHEN discountoffercode = '91' THEN ordertotal END) AS SalesQuadGfx, COUNT(CASE WHEN discountoffercode = '92' THEN 1 END) 
  7.                       AS OrdersATT, SUM(CASE WHEN discountoffercode = '92' THEN ordertotal END) AS SalesATT, 
  8.                       COUNT(CASE WHEN discountoffercode = '93' THEN 1 END) AS OrdersGlobalCrossing, SUM(CASE WHEN discountoffercode = '93' THEN ordertotal END) 
  9.                       AS SalesGlobalCrossing, COUNT(CASE WHEN discountoffercode = '94' THEN 1 END) AS OrdersPerformics, 
  10.                       SUM(CASE WHEN discountoffercode = '94' THEN ordertotal END) AS SalesPerformics, COUNT(CASE WHEN discountoffercode = 'AA' THEN 1 END) 
  11.                       AS OrdersOzburnHessey, SUM(CASE WHEN discountoffercode = 'AA' THEN ordertotal END) AS SalesOzburnHessey, 
  12.                       COUNT(CASE WHEN discountoffercode = 'AB' THEN 1 END) AS OrdersFry, SUM(CASE WHEN discountoffercode = 'AB' THEN ordertotal END) 
  13.                       AS SalesFry, COUNT(CASE WHEN discountoffercode = 'AC' THEN 1 END) AS OrdersEMC, 
  14.                       SUM(CASE WHEN discountoffercode = 'AC' THEN ordertotal END) AS SalesEMC, COUNT(CASE WHEN discountoffercode = 'AD' THEN 1 END) 
  15.                       AS OrdersGlasshouse, SUM(CASE WHEN discountoffercode = 'AD' THEN ordertotal END) AS SalesGlasshouse, 
  16.                       COUNT(CASE WHEN discountoffercode = 'AE' THEN 1 END) AS OrdersSecureWorks, SUM(CASE WHEN discountoffercode = 'AE' THEN ordertotal END) 
  17.                       AS SalesSecureWorks, COUNT(CASE WHEN discountoffercode = 'AF' THEN 1 END) AS OrdersPDS, 
  18.                       SUM(CASE WHEN discountoffercode = 'AF' THEN ordertotal END) AS SalesPDS, COUNT(CASE WHEN discountoffercode = 'AG' THEN 1 END) 
  19.                       AS OrdersMenashaPkg, SUM(CASE WHEN discountoffercode = 'AG' THEN ordertotal END) AS SalesMenashaPkg, 
  20.                       COUNT(CASE WHEN discountoffercode = 'A2' THEN 1 END) AS OrdersBelmark, SUM(CASE WHEN discountoffercode = 'A2' THEN ordertotal END) 
  21.                       AS SalesBelmark, COUNT(CASE WHEN discountoffercode = 'A3' THEN 1 END) AS OrdersPlasticIngeniuty, 
  22.                       SUM(CASE WHEN discountoffercode = 'A3' THEN ordertotal END) AS SalesPlasticIngenuity, COUNT(CASE WHEN discountoffercode = 'A4' THEN 1 END) 
  23.                       AS OrdersUFP, SUM(CASE WHEN discountoffercode = 'A4' THEN ordertotal END) AS SalesUFP, 
  24.                       COUNT(CASE WHEN discountoffercode = 'A5' THEN 1 END) AS OrdersStyrene, SUM(CASE WHEN discountoffercode = 'A5' THEN ordertotal END) 
  25.                       AS SalesStyrene
  26. FROM         dbo.Orders
  27. WHERE     (ReceivedDate BETWEEN '20071114' AND '20071231')
  28. GROUP BY ReceivedDate, OrderStatus
  29.  
Dec 12 '07 #1
1 808
Thanks for the edit :P

um anyone able to help me on this? It is kind of high priority and as i said i can't seem to figure it out
Dec 13 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: netpurpose | last post by:
I need to extract data from this table to find the lowest prices of each product as of today. The product will be listed/grouped by the name only, discarding the product code - I use...
7
by: Simon Bailey | last post by:
How do you created a query in VB? I have a button on a form that signifies a certain computer in a computer suite. On clicking on this button i would like to create a query searching for all...
4
by: d.p. | last post by:
Hi all, I'm using MS Access 2003. Bare with me on this description....here's the situation: Imagine insurance, and working out premiums for different insured properties. The rates for calculating...
4
by: Alan Lane | last post by:
Hello world: I'm including both code and examples of query output. I appologize if that makes this message longer than it should be. Anyway, I need to change the query below into a pivot table...
36
by: Liam.M | last post by:
hey guys, I have one last problem to fix, and then my database is essentially done...I would therefore very much appreciate any assistance anyone would be able to provide me with. Currently I...
5
by: elitecodex | last post by:
Hey everyone. I have this query select * from `TableName` where `SomeIDField` 0 I can open a mysql command prompt and execute this command with no issues. However, Im trying to issue the...
10
by: aaronrm | last post by:
I have a real simple cross-tab query that I am trying to sum on as the action but I am getting the "data type mismatch criteria expression" error. About three queries up the food chain from this...
11
by: funky | last post by:
hello, I've got a big problem ad i'm not able to resolve it. We have a server running oracle 10g version 10.1.0. We usually use access as front end and connect database tables for data extraction....
4
by: Doris | last post by:
It does not look like my message is posting....if this is a 2nd or 3rd message, please forgive me as I really don't know how this site works. I want to apologize ahead of time for being a novice...
6
by: jsacrey | last post by:
Hey everybody, got a secnario for ya that I need a bit of help with. Access 97 using linked tables from an SQL Server 2000 machine. I've created a simple query using two tables joined by one...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.