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
Peformance Tuning
Audit
Business Intelligence
Clustering
Reporting Services
Developer
General DBA
ASP.NET / ADO.NET

SQL Server 2008 - Worth the Wait

SQL Server’s first significant upgrade in three years features a number of envelope-pushing enhancements and improvements. Which will have the greatest impact on SQL administration and development? More...
Latest Articles

Slowly Changing Dimensions in SQL Server 2005
Audit Data Modifications
SQL Server 2008’s Management Data Warehouse
Same Report but Different Methods in SQL Server Reporting Services ...

More     
 
Latest FAQ's

How to Integrate Performance Monitor and SQL Profiler
SSIS Lookups are Case Sensitive
Convert Number to Words in SSRS
After installing SP2 on SQL Server 2005 x64, when trying to ...

More     
   
Latest Software Reviews

SQL Server DBA Dashboard
SwisSQL DBChangeManager
SQLMesh - SQL Server Search Tool
SoftTreeTech SQL Assistant

More     

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

SQL Server Techniques for Creating a Web Reporting Page — Part 1

By : Louis Duc Nguyen
May 12, 2003
Printer friendly

In this article, I’ll demonstrate how to give web users the ability to search and group data via web reporting pages –- using good old web scripting and SQL Server. No ETL/OLAP tool needed. Before we begin, I need to explain data warehousing. In general, as raw transaction level data accumulates, we summarize the data into a different table. We create an “on-line analytical processing cube”. Web users can then query against this cube, w/o interfering with your actual data feed. Also, the cube contains summarized data, speeding up queries.

For example, suppose your sales manager says, he wants to see Sales by Region, Date, and Employee ID. We would write a stored procedure that summarizes sales by region, date, & employee –- and store it into our cube. Typically, a cube does not have a primary key. But we do need to add a clustered index, so SQL Server’s index engine can work properly. SQL Server will automatically attempt to add a clustered index, if there are primary keys. If a table doesn’t have a clustered index, SQL will treat it as an unordered heap. That is, it MAY do table scans, even if there are indexes available, unless you give it an index hint.

In the following cube, N is the number of sales.

<Create the cube and populate it>

CREATE TABLE [dbo].[Cube] (

[Region] [varchar] (50) NULL ,

[Date] [datetime] NULL ,

[EmpID] [int] NULL ,

[N] [int] NULL

)



insert into cube values('North','2003/7/1',1,10)

insert into cube values('North','2003/7/2',1,8)

insert into cube values('North','2003/7/4',2,6)

insert into cube values('South','2003/7/1',12,5)

insert into cube values('South','2003/7/5',12,6)

insert into cube values('South','2003/7/7',12,33)

insert into cube values('South','2003/7/9',13,2)

insert into cube values('East','2003/7/1',21,1)

insert into cube values('East','2003/7/2',21,3)

insert into cube values('West','2003/7/10',31,22)

insert into cube values('West','2003/7/12',31,2)

insert into cube values('West','2003/7/11',32,13)

insert into cube values('West','2003/7/18',32,23)

insert into cube values('West','2003/7/19',33,4)

</Create the cube and populate it>

Search the Cube

Our sales manager’s first request is to “search” or filter the cube. For example, he wants to be able to select, the “West” region or select ‘All’ regions. Similarly he wants to select employee “21” or select “All” employees. Dates aren’t a big issue, as he only wants to be able to select a date range. In our web page, we provide him with input select boxes. Below is an example input select box for Region, which would be passed into the @Region parameter of our reporting stored procedure “CubeSP”.



<Our Region input select box >

<select name="Region">

<OPTION value="ALL">ALL</option>

<OPTION value="North">North</option>

<OPTION value="East">East</option>

<OPTION value="South">South</option>

<OPTION value="West">West</option>

</select>

</Our Region input select box >

<Our Reporting Stored Procedure>

CREATE PROCEDURE CubeSP

(

@method varchar(50)='sumSales' --:sumSales

,@region varchar(50)='all'

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

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

,@empid varchar(50)='all'

)

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='sumSales' begin

select sumSales=sum(N)

from cube

where [date] between @startdate and @enddate

and region like @region

and empid like @empid

return

end

</Our Reporting Stored Procedure>

 


    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