Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Subtotals??????????

Author  Topic 

DaveC11
Starting Member

43 Posts

Posted - 2008-08-13 : 09:04:54
I've got the following sql statment which works fine. Is it possible to put subtotals in the query so the amount of sales is totaled and grouped by each month???


select convert(varchar(11),createdon, 106),
username + ' ' + surname as 'Consultant',DATENAME(MONTH, invoiceissueddate) AS theMonth,
fileas as 'Applicant',
(CASE WHEN RowNo=1 and placementtypeid not in('6','5','19','26','28')THEN placementfee ELSE 0 END )+ (CASE WHEN RowNo=1 THEN isnull(feereduction,0) ELSE 0 END) as 'Placement Fee' ,
(CASE WHEN RowNo=1 and placementtypeid in('23','17') THEN placementfee ELSE 0 END)+ (CASE WHEN RowNo=1 and placementtypeid in ('24','27','18') THEN isnull(feereduction,0) ELSE 0 END) as 'Drop Outs',
convert(varchar(11),invoiceissueddate, 106)'Invoice Issued Date'

FROM
(
SELECT ROW_NUMBER() OVER (PARTITION BY p.placementid ORDER BY p.placementid) AS RowNo,p.createdon,p.placementfee,p.placementid, p.placementtypeid, ps.feereduction, o.fileas, u.username, u.surname, i.netsum,i.invoiceissueddate, p.startdate
FROM placements p
left join PlacementSectorDefinedColumns ps on ps.placementid = p.placementid
join placementconsultants pc on pc.placementid = p.placementid
join users u on u.userid = pc.userid
join objects o on o.objectid = p.applicantid
left outer join placementinvoices pp on pp.placementid = p.placementid
left join invoices i on i.invoiceid = pp.invoiceid

WHERE p.createdon >= '20080601'
AND p.createdon < '20090701'
AND p.createdon < '20150101' and p.placementtypeid not in ('6','26','28')) tmp

order BY tmp.createdon


Thanks in advance

Dave,

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-08-13 : 09:45:13
can you explain with some data what you're expecting?
Go to Top of Page

DaveC11
Starting Member

43 Posts

Posted - 2008-08-13 : 10:48:17
something along the lines of the below

Month Consultant Placementfee

Jan Con a 1
Jan Con b 2
Total 3
Feb con c 5
Feb con b 5
Feb con a 5
Total 15

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-08-13 : 11:14:58
ok so this is what you want as output. how will be your input data?
Go to Top of Page

DaveC11
Starting Member

43 Posts

Posted - 2008-08-13 : 11:39:49
The data is already in a db. i'm looking for a way to produce an output like the one above. Is it possible?
Go to Top of Page

DaveC11
Starting Member

43 Posts

Posted - 2008-08-13 : 11:39:49
The data is already in a db. i'm looking for a way to produce an output like the one above. Is it possible?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-08-13 : 11:44:35
i asked how data is organised in your tables. can you illustrate some data from tables involved?
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-08-14 : 05:36:41
quote:
Originally posted by DaveC11

The data is already in a db. i'm looking for a way to produce an output like the one above. Is it possible?


Where do you want to show data?
If you use reports, do this there

Otherwise read about Rollup operator in sql server help file

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -