SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Counting tickets per customer per month (basic)
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

urmas80
Starting Member

13 Posts

Posted - 02/22/2013 :  04:11:06  Show Profile  Reply with Quote
Hi All, I believe, I have a basic question:
Trying to count tickets per client per month, expected result:

January 3 Customer 1
January 15 Customer 2
January 1 Customer 3
February 15 Customer 1
February 10 Customer 2
February 2 Customer 3

But instead i just getting :

January 1 Customer 1
January 1 Customer 2
January 1 Customer 3
February 1 Customer 1
February 1 Customer 2
February 1 Customer 3

This is my query:

SELECT DATENAME(MONTH,datetimeOpened)AS PerMonth,
COUNT(fldIWfId) AS Tickets,
OrganizationfldName AS Customer
FROM mytable
WHERE datetimeOpened > dateadd(year, -1, GETDATE())
GROUP by OrganizationfldName, fldIWfId, datetimeOpened
Order BY PerMonth desc


Thank you in advance,

U

Abu-Dina
Posting Yak Master

United Kingdom
206 Posts

Posted - 02/22/2013 :  04:22:52  Show Profile  Reply with Quote
SELECT DATENAME(MONTH,datetimeOpened)AS PerMonth, 
COUNT(fldIWfId) AS Tickets,
OrganizationfldName AS Customer 
FROM mytable
WHERE datetimeOpened > dateadd(year, -1, GETDATE())
GROUP by DATENAME(MONTH,datetimeOpened), OrganizationfldName, 
Order BY PerMonth desc
Go to Top of Page

urmas80
Starting Member

13 Posts

Posted - 02/22/2013 :  06:26:14  Show Profile  Reply with Quote
Thanks! so simple...
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000