Autor Beitrag
Timbo
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 166



BeitragVerfasst: Do 01.06.06 13:26 
Hallo, ich hab mal wieder ein SQL Problem.

Tabelle:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
 Nr VK    MwSt 
 1  2,00    7
 1  5,00   16
 2  6,00    7
 2  3,00    7


das möchte ich haben
ausblenden Delphi-Quelltext
1:
2:
3:
 Nr VK    Netto
 1  7,00   6,18
 2  9,00   8,41


man beachte, das bei Nr: 1 ein teil mit 2,00 mit 7% gerechnet wird und 5,00 mit 16%:
(2,00 / 1,07) + (5,00 / 1,16) = 6,18

Hat jemand eine Idee?

Vielen Dank.
Timbo Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 166



BeitragVerfasst: Do 01.06.06 13:37 
Ich habs, hatte gerade einen Geistesblitz...
ausblenden SQL-Anweisung
1:
2:
SELECT Nr, Sum(VK) as VK, Sum(VK / (1+(MwSt/100))) as Netto
FROM Tabelle Group By Nr


Der Knackpunkt ist, das Sum um den komplette Ausdruck zu legen.


Zuletzt bearbeitet von Timbo am Do 01.06.06 13:47, insgesamt 1-mal bearbeitet
digi_c
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1905

W98, XP
D7 PE, Lazarus, WinAVR
BeitragVerfasst: Do 01.06.06 13:38 
SELECT Nr,(VK*MwST)AS Netto FROM TABELLE WHERE ...

Oder ist mein Hirn verkalkt?
Timbo Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 166



BeitragVerfasst: Do 01.06.06 13:48 
Das Group By hast Du vergessen...
raiguen
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 374

WIN 2000prof, WIN XP prof
D7EP, MSSQL, ABSDB
BeitragVerfasst: Do 01.06.06 15:42 
Moin :)
user profile icondigi_c hat folgendes geschrieben:
SELECT Nr,(VK*MwST)AS Netto FROM TABELLE WHERE ...

Oder ist mein Hirn verkalkt?

Über den allgemeinen Verkalkungsgrad Deines Hirns vermag ich keine Aussagen zu treffen; aber im Speziellen schon ;-)
(VK*MwST)AS Netto ist insofern falsch, weil VK bereits die Mehrwertsteuer enthält, somit als BruttoWert anzusehen ist. Bei Deiner Berechnung käme beispielsweise für VK=10 und MwST=16 als Netto 160 heraus :roll:
Die Formel Sum(VK / (1+(MwSt/100))) as Netto von user profile iconTimbo ist da schon die richtige :!:
digi_c
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1905

W98, XP
D7 PE, Lazarus, WinAVR
BeitragVerfasst: Fr 02.06.06 06:57 
Ach Mensch "Mittagsstund hat Blei im Mund" ;)