Click here to Skip to main content
15,889,909 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi friends,
i wrote StoredProcedure for weekly data
and i want to sum of records in row not column
i dont know how to do, so please check my sp and give me solution for this,
my sP's printed query is here,

XML
select CourseName
         , Sum([Week0]) as [Week Start - 20 Aug 10]
         , Sum([Week1]) as [Week Start - 27 Aug 10]
         , Sum([Week2]) as [Week Start - 03 Sep 10]
from (select CourseName
         , case when StartDate >= '08/20/2010' and StartDate < '08/27/2010'
                then COUNT(CourseName) else 0 end as [Week0]
         , case when StartDate >= '08/27/2010' and StartDate < '09/03/2010'
                then COUNT(CourseName) else 0 end as [Week1]
         , case when StartDate >= '09/03/2010' and StartDate < '09/10/2010'
                then COUNT(CourseName) else 0 end as [Week2]
from GL_BookingList bl
    inner join GL_MasterPriceDefaultSelection mpds on bl.PriceItemId=mpds.PriceItemId
    inner join GL_Course on GL_Course.CourseID= mpds.SelectionId
where (GL_Course.StartDate >= '08/16/2010' and GL_Course.StartDate < '09/11/2010')
group by CourseName,GL_Course.StartDate)as t
    group by CourseName

CourseName...WeekStart-20 Aug 2010. . .WeekStart-27 Aug 2010. . .WeekStart-03 sep 2010
C language. . . . . . . . . . . 2. . . . . . . . . . . . . . . . . . . . . . . . . .0 . . . . . . . . . . . . . . . . . . . . 11
C++. . . . . . . . . . . .2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3 . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Total. . . . . . . . . . . . . . . . . 4. . . . . . . . . . . . . . . . . . . . . . . . .3 . . . . . . . . . . . . . . . . . . . . . 16
_________
i want this type of result. please check it..
don't see dots..i put it for format,
Posted
Comments
Laiju k 7-Nov-14 0:17am    
give full query
Rajesh waran 7-Nov-14 0:29am    
can u provide your table structure with some sample entries?
Manish Dalwadi 7-Nov-14 1:37am    
thank you friends for give me your best time and give me response
i searched and tried once again and i solved it with this
______________________
select CourseName
, Sum([Week0]) as [Week Start - 07 Nov 14]
, Sum([Week1]) as [Week Start - 14 Nov 14]
, Sum([Week2]) as [Week Start - 21 Nov 14] from (select CourseName
, case when StartDate >= '11/03/2014' and StartDate < '11/10/2014' then COUNT(CourseName) else 0 end as [Week0]
, case when StartDate >= '11/10/2014' and StartDate < '11/17/2014' then COUNT(CourseName) else 0 end as [Week1]
, case when StartDate >= '11/17/2014' and StartDate < '11/24/2014' then COUNT(CourseName) else 0 end as [Week2]from GL_BookingList bl
inner join GL_MasterPriceDefaultSelection mpds on bl.PriceItemId=mpds.PriceItemId
inner join GL_Course on GL_Course.CourseID= mpds.SelectionId where (GL_Course.StartDate >= '11/03/2014' and GL_Course.StartDate < '11/29/2014') group by CourseName,GL_Course.StartDate)as t group by CourseName with rollup

1 solution

Here is simple example, may be this will help you.

SQL
select institue.* from
(
    select course_name
            , Sum([Week0]) as [Week Start - 20 Aug 10]
            , Sum([Week1]) as [Week Start - 27 Aug 10]
            , Sum([Week2]) as [Week Start - 03 Sep 10]
    from course group by course_name
) institue

union all

select 'total' as course_name,
    , Sum([Week0]) as [Week Start - 20 Aug 10]
    , Sum([Week1]) as [Week Start - 27 Aug 10]
    , Sum([Week2]) as [Week Start - 03 Sep 10]
from course



description :
--> In first query you need to bring your data with the use of SUM for weeks and make course name in GROUP BY.
--> In second query you need to user UNION ALL and type your query to fetch only one record for only SUM of above all.
--> You need to modify above query with your table structure.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900