Please provide test data in consumable format in future.It may seem like a bit of an effort, but people will be more inclined to answer your question.CREATE TABLE #t( id int NOT NULL ,value int NOT NULL ,[datetime] datetime NOT NULL ,branchid int NOT NULL);INSERT INTO #tVALUES (1, 21, '20150101', 1) ,(2, 25, '20150102', 1) ,(3, 25, '20150103', 1) ,(4, 254, '20150104', 1) ,(5, 21, '20150105', 1) ,(6, 20, '20150106', 1) ,(7, 54, '20150107', 1) ,(8, 21, '20150101', 2) ,(9, 25, '20150102', 2) ,(10, 215, '20150103', 2) ,(11, 25, '20150104', 2) ,(12, 25, '20150105', 2) ,(13, 24, '20150106', 2) ,(14, 48, '20150107', 2);
The following seems to work:DECLARE @Today datetime = '20150101'; --DATEADD(day, DATEDIFF(day, 0, CURRENT_TIMESTAMP), 0);SELECT branchid ,SUM(CASE WHEN [datetime] = @Today THEN value ELSE 0 END) AS TodayValue ,SUM(CASE WHEN [datetime] = @Today + 1 THEN value ELSE 0 END) AS TomorrowValue ,SUM(CASE WHEN [datetime] BETWEEN @Today + 2 AND @Today + 6 THEN value ELSE 0 END) AS NextDaysVallueFROM #tGROUP BY branchid;