PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > mysql.general > Need a *little* with a procedure
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Need a *little* with a procedure

Réponse
 
LinkBack Outils de la discussion
Vieux 11/12/2007, 01h21   #1
Daniel Kasak
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Need a *little* with a procedure

Greetings.

I have 1 procedure that summarises data in a table for one particular
location. It accepts the location ID, and returns the summary as a
single record. It works well.

Now I'm trying to write a procedure that selects all location IDs, and
calls this 1st procedure for every single location, outputting a summary
record per location.

Here is this procedure:

---

CREATE DEFINER=`root`@`10.146.%` PROCEDURE `sp_GasPostingSummary`()
BEGIN

declare done int default 0;
declare LocID int;
declare my_locations cursor for select LocID from GasLocations;
declare continue handler for not found set done = 1;


open my_locations;

repeat
fetch my_locations into LocID;
if not done then
call sp_GasProjectedAnnualConsumption( LocID );
end if;
until done end repeat;

close my_locations;

END

---

When I call it, instead of getting the results, I get lots of empty
sets:

Empty set (0.04 sec)

Empty set (0.04 sec)

Empty set (0.04 sec)

How do I get this above procedure to grab results from the 1st one
( below ), and output them to the client?

Here's the 1st procedure:

---

CREATE DEFINER=`root`@`10.146.%` PROCEDURE
`sp_GasProjectedAnnualConsumption`( in GasLocationID int )
BEGIN

/* Declare variables */
declare MaxBillDate date;
declare TotalConsumption double;
declare TotalSpend double;
declare TotalDays int;

/* Get the last bill date */
select max(BillDate) from GasPosting GP inner join GasAccountNo GA
on GP.AcctNoID = GA.AcctNoID
where GA.LocID = GasLocationID into MaxBillDate;

/* Get consumption data for a year prior to this date */
select
sum( TotalUnits ) /
case
when UnitType = 1 then 1000 /* Megajoules */
when UnitType = 2 then 1 /* Gigajoules */
when UnitType = 3 then 0.0036 /* kWh */
else 1 /* ? */
end as SumTotalConsumption,
sum( TotalBill ) as SumTotalBill,
sum( case when Days > 0 then Days else 28 end ) as SumTotalDays
from GasPosting GP inner join GasAccountNo GA
on GP.AcctNoID = GA.AcctNoID
where LocID = GasLocationID
and BillDate between date_sub( MaxBillDate, interval 1 year ) and
MaxBillDate
into TotalConsumption, TotalSpend, TotalDays;

/* Stretch to 365 days */
select
concat_ws( ', ', Address, Suburb ) as FullAddress,
MIRN,
round( TotalConsumption * 365 / TotalDays ) as
ProjectedAnnualConsumption,
round( TotalSpend * 365 / TotalDays ) as ProjectedAnnualSpend
from
GasLocations
where
LocID = GasLocationID;

END

---


--
Daniel Kasak
IT Developer
NUS Consulting Group
Level 5, 77 Pacific Highway
North Sydney, NSW, Australia 2060
T: (+61) 2 9922-7676 / F: (+61) 2 9922 7989
email: dkasak@nusconsulting.com.au
website: http://www.nusconsulting.com.au

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 06h55.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,07926 seconds with 9 queries