|
database
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
GROUP BY and populating temp table, ideas?I have the following table, and want to create a report as seen below. CREATE TABLE [dbo].[Sales] ( [ACTIVITY_ID] [varchar] (16) NOT NULL , [CREATED_BY] [varchar] (10) NULL, [YEAR] [varchar] (9) NULL , [PERIOD] [varchar] (2) NULL , [WEEK] [char] (1) NULL , [AMOUNT] [varchar] (3) NULL ) ON [PRIMARY] GO I need to see count(*) of each rep for each week and current preriod. Something like this: REP_NAME Week1 Week2 Week3 Week4 Week5 Period(Month) ======== ===== ===== ===== ===== ===== ============= DAVID 5 10 5 20 WILLIAM 2 8 5 15 JANE 10 2 10 22 Do I need to run seperate group by's for each week and populate a temp table? Or there can be a simpler way to do that? Thanks, Ada -- SQL Server DBA First of all, pivoting data for presentation purposes does not belong on the
data layer. But if you really, really, really need to do it in T-SQL read this: http://www.windowsitpro.com/Article/ArticleID/15608/15608.html?Ad=1 ML |
|||||||||||||||||||||||