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
 SQL Server 2012 Forums
 Transact-SQL (2012)
 SQL Query Help
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

tooba
Posting Yak Master

172 Posts

Posted - 05/08/2013 :  22:43:06  Show Profile  Reply with Quote
Here is the sample data that i have


Name FILE Weekday COUNT
Shelb Receive 5/6/2013 Monday 104
Feli Receive 4/21/2013 Sunday 11
Shelb Send 4/23/2013 Tuesday 2
Jan Receive 4/27/2013 Saturday 12
Tris Send 5/4/2013 Saturday 3
Iri Receive 5/5/2013 Sunday 11
Shelb Receive 5/5/2013 Sunday 11
Lis Receive 4/25/2013 Thursday 92
Lar Send 5/2/2013 Thursday 122
Tony Receive 4/22/2013 Monday 134
Gracd Receive 5/5/2013 Sunday 6
Janet Receive 4/25/2013 Thursday 114
Franda Receive 4/24/2013 Wednesday 153
Johb Send 4/26/2013 Friday 25
Norc Receive 4/30/2013 Tuesday 144



I want end result would be like this

NAME,FILE,MONDAY,TUESDAY,WEDNESDAY,THURSDAY,FRIDAY,SATURDAY,SUNDAY,
IRISP,SEND,count,count, count, count, count, count, count,
IRISP,RECEIVED,count,count, count, count, count, count, count,

All Users.....
I want to group by NAME,FILE,AND DATE, I want to create a report where i can compare all users Send and Receive Count. The data is only
two weeks. Weekday would be like this "date+weekday" and Count is already Counted How many he/she receive and Send per day/date.
Any help would be Great appreciate.

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 05/09/2013 :  00:47:26  Show Profile  Reply with Quote

SELECT *
FROM
(
SELECT Name,File,
STUFF(Weekday,1,CHARINDEX(' ',Weekday),'') AS Weekday,
SUM([COUNT]) AS [COUNT]
FROM Table
GROUP BY Name,File
)m
PIVOT (SUM([COUNT]) FOR WeekDay IN ([Monday],[Tuesday],[Wednesday],[THURSDAY],[FRIDAY],[SATURDAY],[SUNDAY]))p


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs

Edited by - visakh16 on 05/09/2013 00:47:44
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.05 seconds. Powered By: Snitz Forums 2000