Delphi-PRAXiS
Seite 4 von 4   « Erste     234   

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Datenbanken (https://www.delphipraxis.net/15-datenbanken/)
-   -   Delphi aktuelles Mwst.-Problem [SQL] (https://www.delphipraxis.net/51419-aktuelles-mwst-problem-%5Bsql%5D.html)

marabu 8. Sep 2005 10:35

Re: aktuelles Mwst.-Problem [SQL]
 
Hallo Alex,

mit oder ohne colon ist in IB6 egal - ist das beim FB15 anders?

Mit colon ist irgenwie konsistenter, er signalisiert ja sowas wie eine Dereferenzierung - den Zugriff auf den Inhalt.

Freundliche Grüße vom marabu

Hansa 8. Sep 2005 11:37

Re: aktuelles Mwst.-Problem [SQL]
 
An den Doppelpunkten liegts echt nicht. Ich habe den Fehler eingekreist :

SQL-Code:
CREATE TABLE MWST8 (
    ID              INTEGER NOT NULL,
    ABDATUM         DATE,
    MWSTSATZ        SMALLINT,
    MWSTWERT        DECIMAL(15,2),
    ANGELEGT        TIMESTAMP,
    LETZTEAENDERUNG TIMESTAMP
);


INSERT INTO MWST8 (ID, ABDATUM, MWSTSATZ, MWSTWERT, ANGELEGT, LETZTEAENDERUNG) VALUES (1, '1998-04-01', 2, 16, '2005-09-03 12:26:31', NULL);
INSERT INTO MWST8 (ID, ABDATUM, MWSTSATZ, MWSTWERT, ANGELEGT, LETZTEAENDERUNG) VALUES (2, '1998-04-01', 1, 7, '2005-09-03 12:26:47', NULL);
INSERT INTO MWST8 (ID, ABDATUM, MWSTSATZ, MWSTWERT, ANGELEGT, LETZTEAENDERUNG) VALUES (3, '2005-04-01', 2, 18, '2005-04-01 00:00:00', '2005-09-04 16:50:21');
INSERT INTO MWST8 (ID, ABDATUM, MWSTSATZ, MWSTWERT, ANGELEGT, LETZTEAENDERUNG) VALUES (4, '1900-01-01', 2, 15, '2005-09-03 13:55:15', NULL);

COMMIT WORK;



/******************************************************************************/
/****                          Stored Procedures                          ****/
/******************************************************************************/


SET TERM ^ ;

ALTER PROCEDURE MWSTWERTSP8 (
    MONAT SMALLINT,
    JAHR SMALLINT,
    MWSTSATZ SMALLINT)
RETURNS (
    MWSTWERT NUMERIC(9,2))
AS
DECLARE VARIABLE DATUM DATE;
BEGIN
  DATUM = CAST('01.'|| MONAT || '.' || JAHR AS DATE);
  SELECT FIRST 1 
    MWSTWERT
  FROM
    MWST8
  WHERE
    (MWSTSATZ=:MWSTSATZ) AND (ABDATUM <= :DATUM)
  ORDER BY
    ABDATUM DESC
  INTO
    :MWSTWERT;
  IF (MWSTSATZ is null) THEN
    MWSTSATZ = 0;
MWSTWERT = 10; <-------------------------------------------
  SUSPEND;
END
^
Setze ich den MWSTWERT von Hand auf 10 (siehe oben), dann stimmt auch der Bruttoumsatz auf der Grundlage von 10 % Mwst. Die verwendeten Testdaten sind auch dabei. Gebe ich 100 ein so kommt 110 dabei raus. Mache ich das nochmals dann ist es 220. Also richtig. Lasse ich den MWSTWERT von der SP ermitteln, ohne diese Zeile, dann gehts nicht. 8)

alex517 8. Sep 2005 11:40

Re: aktuelles Mwst.-Problem [SQL]
 
Hi marabu,

Zitat:

Zitat von marabu
mit oder ohne colon ist in IB6 egal - ist das beim FB15 anders?

Beim Zugriff auf Variablen in assignment statements einer SP wird laut Manual IB6
colon nicht gesetzt.
Im Gegensatz zu SELECT/UPDATE/INSERT.. -statements.

Zitat:

DataDef.pdf, CHAPTER 9 WORKING WITH STORED PROCEDURES INTERBASE 6

Using assignment statements
---------------------------
A procedure can assign values to variables with the syntax:
variable = expression;
where expression is any valid combination of variables, operators, and expressions, and
can include user-defined functions (UDFs) and generators.
A colon need not precede the variable name in an assignment statement. For example,
the following statement assigns a value of zero to the local variable, ANY_SALES:
any_sales = 0;

Variables should be assigned values of the datatype that they are declared to be. Numeric
variables should be assigned numeric values, and character variables assigned character
values. InterBase provides automatic type conversion. For example, a character variable
can be assigned a numeric value, and the numeric value is automatically converted to a
string. For more information on type conversion, see the Embedded SQL Guide.



Using SELECT statements
-----------------------
In a stored procedure, use the SELECT statement with an INTO clause to retrieve a single
row value from the database and assign it to a host variable. The SELECT statement must
return at most one row from the database, like a standard singleton SELECT. The INTO
clause is required and must be the last clause in the statement.
For example, the following statement is a standard singleton SELECT statement in an
application:
EXEC SQL
SELECT SUM(BUDGET), AVG(BUDGET)
INTO :tot_budget, :avg_budget
FROM DEPARTMENT
WHERE HEAD_DEPT = :head_dept;

To use this SELECT statement in a procedure, move the INTO clause to the end as follows:
SELECT SUM(BUDGET), AVG(BUDGET)
FROM DEPARTMENT
WHERE HEAD_DEPT = :head_dept
INTO :tot_budget, :avg_budget;

For a complete discussion of SELECT statement syntax, see the Language Reference.


Die SP läßt sich zwar im Falle von Hansa compilieren, aber bei Verwendung des
Doppelpunktes ist ":UMSATZ" gleich NULL.
Damit ist auch das Ergebnis der Zuweisung gleich NULL.

VAR_UMSATZBRUTTO = NULL * (1 + VAR_MWSTWERT / 100) --> NULL


alex

marabu 8. Sep 2005 12:38

Re: aktuelles Mwst.-Problem [SQL]
 
Alex, da steht "need not" und nicht "must not". Ich habe mir die Verwendung des colon auch in assignments aus dem angegebenen Grund angewöhnt. Sobald der Parser geändert wird, werde ich es mir wieder abgewöhnen müssen, aber bis dahin: es funktioniert bei mir.

marabu

marabu 8. Sep 2005 12:55

Re: aktuelles Mwst.-Problem [SQL]
 
Hansa, du solltest vielleicht Namensüberdeckungen vermeiden:

SQL-Code:
CREATE PROCEDURE MWSTWERTSP8 (
  iMONAT SMALLINT,
  iJAHR SMALLINT,
  iMWSTSATZ SMALLINT )
RETURNS (
  oMWSTWERT NUMERIC(9,2) )
AS
  DECLARE VARIABLE vDATUM DATE;
  DECLARE VARIABLE vMWSTWERT NUMERIC(9,2);
BEGIN
  vDATUM = CAST('01.'|| iMONAT || '.' || iJAHR AS DATE);
  SELECT FIRST 1 mwstwert
    FROM mwst8
    WHERE (mwstsatz = :iMWSTSATZ) AND (abdatum <= :vDATUM)
    ORDER BY abdatum DESC
    INTO :vMWSTWERT;
  oMWSTWERT = :vMWSTWERT;
  SUSPEND;
END
marabu (getippt und nicht getestet)

alex517 8. Sep 2005 13:02

Re: aktuelles Mwst.-Problem [SQL]
 
Zitat:

da steht "need not" und nicht "must not".
Das habe ich gelesen. Und aus diesem Grund colon in assignments auch nicht verwendet. ;-)
In FB ist scheinbar aus dieser "Empfehlung" ein Muß geworden.

alex

marabu 8. Sep 2005 13:14

Re: aktuelles Mwst.-Problem [SQL]
 
Alex, wenn das stimmt, dass der FB Parser an der Stelle nicht mehr kompatibel zum IB Parser ist, dann frage ich mich, wie Hansa getestet hat. FB hat er offensichtlich genommen, denn sonst wäre er ja über FIRST gestolpert.

Zitat:

Zitat von Hansa
An den Doppelpunkten liegts echt nicht

marabu

alex517 8. Sep 2005 14:37

Re: aktuelles Mwst.-Problem [SQL]
 
Hi Hansa, hi marabu,

Ihr habt beide Recht an den Doppelpunkten liegts nicht.

Hansa, sieh dir doch mal die Parameterreihenfolge der
MWSTWERTSP8-Deklaration und beim Aufruf der MWSTWERTSP8
an:
SQL-Code:
CREATE PROCEDURE MWSTWERTSP8 (
    MONAT SMALLINT,
    JAHR SMALLINT,
    MWSTSATZ SMALLINT)
RETURNS (
    MWSTWERT NUMERIC(9,2))
SQL-Code:
  SELECT MWSTWERT FROM MWSTWERTSP8 (:MWSTSATZ,:MONAT,:JAHR) INTO :VAR_MWSTWERT;
alex


Alle Zeitangaben in WEZ +1. Es ist jetzt 15:22 Uhr.
Seite 4 von 4   « Erste     234   

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz