Drop Table

Support Forum for database administrators and web based access to important newsgroups related to databases
Register on Database Support Forum Edit your profileCalendarFind other Database Support forum membersFrequently Asked QuestionsSearch this forum -> 
For Database admins: Free Database-related Magazines Now Free shipping to Texas


Post New Thread










Thread
Author

Generate 'calculated values' for rows within Stored Procedure
I'm having a problem with generating a 'calculated' percentage value as
noted in the sample output below:

#######
Luxury		822	.34602709630
Standard	433	.34602709630
Custom		397	.34602709630
Modified	285	.34602709630
Other		222	.34602709630

More...		676	.34602709630
#######

The 'VP_VClass' column (left) correctly shows each classification, and
provides the correct count for each. However the percentage for each
classification is shown 'incorrectly' as it should be a percentage for each
instead of for the 'sum' of the classifications count, like so:

#######
Luxury		822	.10032954961
Standard	433	.05284999389
#######

The SP is as follows, where the function [dbo. udf_Current_Inventor
yFunction
()] provides the 'total' count (which in the examples above is 8,193).

#######
ALTER PROCEDURE dbo. usp_VClass_Breakdown

AS
SELECT     TOP 100 PERCENT VP_VClass, COUNT(VP_VClass) AS CountOfVP_VClass,
(SELECT      CAST(COUNT(VP_VClass
) AS NUMERIC)
FROM          dbo. vw_VClass_BreakdownV
iew
WHERE      (Active = 1) AND (Current = 1)) /
(SELECT     *
FROM          dbo. udf_Current_Inventor
yFunction
()) AS Expr1
FROM         dbo. vw_VClass_BreakdownV
iew
WHERE     (Active = 1) AND (Current = 1)
GROUP BY VP_VClass
ORDER BY COUNT(VP_VClass) DESC
#######

Any thoughts or suggestions would be appreciated. Thanks.

--
Message posted via http://www.webservertalk.com

Report this thread to moderator Post Follow-up to this message
Old Post
The Gekkster via webservertalk.com
04-28-05 01:23 AM


RE: Generate 'calculated values' for rows within Stored Procedure
Hi,
The Query can be re-written as:
 ====================
=========
ALTER PROCEDURE dbo. usp_VClass_Breakdown

AS
SELECT  VP_VClass, COUNT(VP_VClass) AS CountOfVP_VClass, COUNT(VP_VClass) /
 udf_Current_Inventor
yFunction() PercentOfVP
FROM dbo. vw_VClass_BreakdownV
iew
WHERE     (Active = 1) AND (Current = 1)
GROUP BY VP_VClass
ORDER BY COUNT(VP_VClass) DESC
================

I believe this addressed your question. If there are any more problem please
revert back

thanks and regards
Chandra

"The Gekkster via webservertalk.com" wrote:

> I'm having a problem with generating a 'calculated' percentage value as
> noted in the sample output below:
>
> #######
> Luxury		822	.34602709630
> Standard	433	.34602709630
> Custom		397	.34602709630
> Modified	285	.34602709630
> Other		222	.34602709630
>
> More...		676	.34602709630
> #######
>
> The 'VP_VClass' column (left) correctly shows each classification, and
> provides the correct count for each. However the percentage for each
> classification is shown 'incorrectly' as it should be a percentage for eac
h
> instead of for the 'sum' of the classifications count, like so:
>
> #######
> Luxury		822	.10032954961
> Standard	433	.05284999389
> #######
>
> The SP is as follows, where the function [dbo. udf_Current_Inventor
yFunctio
n
> ()] provides the 'total' count (which in the examples above is 8,193).
>
> #######
> ALTER PROCEDURE dbo. usp_VClass_Breakdown

> AS
> SELECT     TOP 100 PERCENT VP_VClass, COUNT(VP_VClass) AS CountOfVP_VClass
,
>                           (SELECT      CAST(COUNT(VP_VClass
) AS NUMERIC)
>                             FROM          dbo. vw_VClass_BreakdownV
iew
>                             WHERE      (Active = 1) AND (Current = 1)) /
>                           (SELECT     *
>                             FROM          dbo. udf_Current_Inventor
yFunctio
n
> ()) AS Expr1
> FROM         dbo. vw_VClass_BreakdownV
iew
> WHERE     (Active = 1) AND (Current = 1)
> GROUP BY VP_VClass
> ORDER BY COUNT(VP_VClass) DESC
> #######
>
> Any thoughts or suggestions would be appreciated. Thanks.
>
> --
> Message posted via http://www.webservertalk.com
>

Report this thread to moderator Post Follow-up to this message
Old Post
Chandra
04-28-05 08:23 AM


RE: Generate 'calculated values' for rows within Stored Procedure
Hi Chandra,

Thanks for the assist - that took care of it.

--
Message posted via http://www.webservertalk.com

Report this thread to moderator Post Follow-up to this message
Old Post
The Gekkster via webservertalk.com
04-28-05 02:23 PM


RE: Generate 'calculated values' for rows within Stored Procedure
Good to know that the solution addressed your needs. Really appreciate if yo
u
can rate the Post.

This can be done by answering "Was this post helpful to you?"




"The Gekkster via webservertalk.com" wrote:

> Hi Chandra,
>
> Thanks for the assist - that took care of it.
>
> --
> Message posted via http://www.webservertalk.com
>

Report this thread to moderator Post Follow-up to this message
Old Post
Chandra
04-29-05 08:23 AM


Sponsored Links





Last Thread Next Thread
Post New Thread

MS SQL Server archive

Show a Printable Version Email This Page to Someone! Receive updates to this thread
Microsoft SQL Server
Access database support
PostgreSQL Replication
SQL Server ODBC
FoxPro Support
PostgreSQL pgAdmin
SQL Server Clustering
MySQL ODBC
Web Applications with dBASE
SQL Server CE
MySQL++
Sybase Database Support
MS SQL Full Text Search
PostgreSQL Administration
SQL Anywhere support
DB2 UDB Database
Paradox Database Support
Filemaker Database
Berkley DB
SQL 2000/2000i database
ASE Database
Forum Jump:
All times are GMT. The time now is 08:42 PM.

 
Mobile devices forum | Database support forum archive




Copyrights DropTable.com Database Support Forum 2004 - 2006