Site sponsored by: Idera Try Idera’s new SQL admin toolset
SQL Server Performance

  • Home
  • Articles
  • Forums
  • Tips
  • Quiz
  • FAQ's
  • Blogs
  • Software
  • Books
  • About Us
RSS Feeds
Sign in | Join


Article Topics

All Articles
Performance Tuning
Audit
Business Intelligence
Clustering
Reporting Services
Developer
General DBA
ASP.NET / ADO.NET

Write for Us

Share you SQL Server knowledge with others and raise your profile in the community More...
Latest Articles

Resource Governor in SQL Server 2008
Tweaks in SQL Server Reporting Services
Configure Filestream in SQL Server 2008
Capture DDL Changes using Change Data Capture with SQL Server 2008 ...

More     
 
Latest FAQ's

SQL Server Reporting Server (SSRS) service is failing to start ...
Cannot Start SQL Server Service
Users are able to connect to report manager but not able ...
Errors when SQL Server Snapshot Replication is Running

More     
   
Latest Software Reviews

Spotlight on ApexSQL Doc 2008
ApexSQL Enforce
Embarcadero Change Manager
SQL Server DBA Dashboard

More     

articles >> developer >> SQL Server Techniques for Creating a Web ...

SQL Server Techniques for Creating a Web Reporting Page -- Part 2

By : Louis Duc Nguyen
Jun 22, 2003

Page 2 / 3

TOTAL ROW

Our sales manager requests, that when he groups by region and/or empid, that a total row be added to the bottom of the result set. We can accomplish this using many techniques. In this article I’ll demonstrate how to (a) call a stored procedure from a stored procedure and (b) share temp tables. Essentially I plan to convert the existing “groupSales” method code block into a drone. It cannot execute by itself; a master method must call upon it to execute. I will create a new method code block “groupSalesWithTotal”. This method will call upon “groupSales” once to create the body of the result set. If needed, it will call upon “groupSales” again to add the total row. Internally, I will also add a new parameter @type, which will distinguish between the “body” and the “total”.

<Our Reporting Stored Procedure>

ALTER PROCEDURE CubeSP

(

@method varchar(50)='groupSalesWithTotal'

,@region varchar(50)='all'

,@startdate datetime='1900/1/1'

,@enddate datetime='2100/1/1'

,@empid varchar(50)='all'

,@group varchar(5000)=null

,@orderby varchar(5000)='region,empid'

,@type varchar(50)=null

)

AS

SET NOCOUNT ON

SET ANSI_WARNINGS OFF

SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED

select @region=case when @region='all' then '%' else @region end

select @empid=case when @empid='all' then '%' else @empid end

 

if @method='groupSales' begin

insert into #R (type,region,empid,sumSales)

select type=@type,region,empid,sumSales=sum(N)

from

(

select

region=case when patindex('%region%',@group)>0 then region else '' end

,empid=case when patindex('%empid%',@group)>0 then empid else 0 end

,n

from cube

where [date] between @startdate and @enddate

and region like @region

and empid like @empid

) as a

group by region,empid

order by

case when patindex('%desc%',@orderby)>0 and patindex('%region%',@orderby)>0 then region end desc

,case when patindex('%region%',@orderby)>0 then region end

,case when patindex('%desc%',@orderby)>0 and patindex('%empid%',@orderby)>0 then empid end desc

,case when patindex('%empid%',@orderby)>0 then empid end

,case when patindex('%desc%',@orderby)>0 and patindex('%sumSales%',@orderby)>0 then sum(N) end desc

,case when patindex('%sumSales%',@orderby)>0 then sum(N) end

return

end

 

if @method='groupSalesWithTotal' begin

create table #R (type varchar(50),region varchar(50),empid int, sumSales int)

exec CubeSp

@method       ='groupSales'

,@region       =@region

,@startdate   =@startdate

,@enddate     =@enddate

,@empid        =@empid

,@group        =@group

,@orderby      =@orderby

,@type                   ='Body'

 

if @group<>'all' begin

exec CubeSp

@method       ='groupSales'

,@region       =@region

,@startdate   =@startdate

,@enddate     =@enddate

,@empid        =@empid

,@group        ='all'

,@orderby      =@orderby

,@type          ='Total'

end

 

select  * from #R

return

end

</Our Reporting Stored Procedure>


<< Prev Page     Next Page>>    








Home | Peformance Articles | Audit Articles | Business Intelligence Articles | Clustering Articles | Developer Articles | Reporting Services Articles | DBA Articles | ASP.NET / ADO.NET Articles | DBA FAQ's | Developer Peformance FAQ's | DBA Peformance FAQ's | Developer FAQ's | Clustering FAQ's | Error Messages | Audit Tool Reviews | Backup Tool Reviews | Coding Tool Reviews | Compare Tool Reviews | Documentation Tool Reviews | Design Tool Reviews | Monitoring Tool Reviews | Log Tool Reviews | Reporting Tool Reviews | Clustering Tool Reviews | Security Tool Reviews | Change Management Tool Reviews | Remote Access Tool Reviews | Book Reviews | Security Tool Reviews | QDPMA Performance Tuning | ADO.NET / ASP.NET | Administration | Analysis/OLAP Services | Application Development | Configuration | Components | ETL | Hardware | High Availability | Hints | Index | Misc | Operating Systems | Performance Tuning | Replication | T-SQL | Views


              © 1999-2008 by T10 Media. All rights reserved