Advertisement

03.17.2008 at 02:22PM PDT, ID: 23248543
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.9

Is there an alternative to Cursos

Asked by Mehawitchi in SQL Server 2005

Tags: , , ,

Helllo there,

I have a monthly corportae reports which generates around 30 different KPIs (Key Performance Indicators). Each KPI is being generated using a different query from a number of joined tables in a SQL Server database.

In an attempt to automate the report generation process, I've created a table in my database, in which I have stored the variable parts in all the 30 queries for the KPIs.

The table is comprised of the following columns: (This is just a demo table)

KPI_Name     Criteria_1     Criteria_2     Criteria_3
=======     ========     ========     =======
KPI_1          XYZ             ABC               KLM
KPI_2          QWE             GHJ               MNO
KPI_3          ........             .......               ........

The query for KPI_1 is:
Select sum(Sales) from myTable
WHERE 1st_Criteria = 'XYZ' and 2nd_Criteria = 'ABC' and 3rd_Criteria = 'KLM'

The query for KPI_2 is:
Select sum(Sales) from myTable
WHERE 1st_Criteria = 'QWE' and 2nd_Criteria = 'GHJ' and 3rd_Criteria = 'MNO'

and so on and so forth.

The way I plan to generate the report is through a stored procedure, in which I will read the entire contents of my Criteria Table into a Cursor, and then construct my select statement in dynamic SQL:

DECLARE myCursor CURSOR FOR SELECT KPI_Name, Criteria_1, Criteria_2, Criteria_3
FROM myTable

OPEN myCursor
FETCH NEXT FROM myCursor
INTO @KPI_Name, @Criteria_1, @Criteria_2, @Criteria_3

WHILE @@FETCH_STATUS = 0
BEGIN

Declare @SQL as varchar(200)
Set @SQL = 'Insert into Output_Table (KPI_Value) Select sum(Sales) from myTable WHERE
1st_Criteria = ' + @Criteria_1 +
' and 2nd_Criteria = ' + @Criteria_2 +
' and 3rd_Criteria = ' @Criteria_3
exec sp_executesql @SQL

Could you please advise if there is a better to automate the report generation,? Specifically, is there a better alternative to using Cursor to loop through the 30 different KPI queries?

Many thanks in advance for your great support.

Hani



Start Free Trial
[+][-]03.17.2008 at 02:51PM PDT, ID: 21146495

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: SQL Server 2005
Tags: Microsoft, SQL Server, 2005, Cursors / Stored Procedure
Sign Up Now!
Solution Provided By: angelIII
Participating Experts: 2
Solution Grade: A
 
 
[+][-]03.17.2008 at 02:51PM PDT, ID: 21146501

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]03.17.2008 at 03:41PM PDT, ID: 21146933

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.24.2008 at 10:23AM PDT, ID: 21195025

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628