Microsoft SQL Server
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseMicrosoft SQL Server

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old May 10th, 2004, 08:28 AM
Kris_Vanherck's Avatar
Kris_Vanherck Kris_Vanherck is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Location: Belgium, Antwerp
Posts: 177 Kris_Vanherck User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 24 sec
Reputation Power: 5
Angry Calculation errors or MS bug in recursive functions ??

are there know problems with calculation errors in recursive function in sql server 2000 ?

if not, please point out the error in the following:

PHP Code:
 CREATE FUNCTION dbo.func_RecVerkoopprijs_basis (@Parent bigint, @Versie_ID bigint)
RETURNS decimal(10,2) AS
BEGIN
 
DECLARE @Value decimal(10,2)
 IF (@
Parent IS null) OR (@Parent IN (SELECT Parent_ID FROM Offerte_Lijnen WHERE Versie_ID = @Versie_ID))
 
BEGIN
  
IF (@Parent IS null)
  
BEGIN
   SET 
@Value = (SELECT SUM(dbo.func_RecVerkoopprijs_basis(Lijn_ID,Versie_  ID) * (1-Discount)) FROM view_Full_Lijnen WHERE Parent_ID IS null AND Versie_ID = @Versie_ID)
  
END
  
ELSE
  
BEGIN
   SET 
@Value = (SELECT SUM(dbo.func_RecVerkoopprijs_basis(Lijn_ID,Versie_  ID) * (1-Discount)) FROM view_Full_Lijnen WHERE Parent_ID = @Parent)
  
END
 END
 
ELSE
 
BEGIN
  SET 
@Value = (SELECT (Aantal Actuele_Verkoopprijs) as prijs FROM view_Full_Lijnen WHERE Lijn_ID = @Parent and optioneel 0)
 
END
 
RETURN @Value
END 


select dbo.func_recverkoopprijs_basis(25,5) as p
this returns 4193 (wrong because this is supose to be 4220)

Reason why:

select Actuele_Verkoopprijs * Aantal
from view_Full_Lijnen
where Parent_ID=25 AND Versie_ID=5


returns:
400.0000
270.0000
250.0000
3300.0000

THEN:

select sum(Actuele_Verkoopprijs * Aantal)
from view_Full_Lijnen
where Parent_ID=25 AND Versie_ID=5

returns: 4220 (this is right)

EVEN:

select sum(Actuele_Verkoopprijs * Aantal)*(1-(select discount from view_Full_Lijnen where lijn_ID=25 AND Versie_ID=5))
from view_Full_Lijnen
where Parent_ID=25 AND Versie_ID=5


returns: 4220 (still right)

And yet the salst statement should do the exact same thing the function does

anyone any clue

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseMicrosoft SQL Server > Calculation errors or MS bug in recursive functions ??


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT