Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Bases de datos > Firebird e Interbase
Registrarse FAQ Miembros Calendario Guía de estilo Buscar Temas de Hoy Marcar Foros Como Leídos

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 06-08-2015
novato_erick novato_erick is offline
Miembro
 
Registrado: ago 2010
Ubicación: Panamá
Posts: 396
Poder: 14
novato_erick Va por buen camino
variable de Tipo Decimal envia error

Hola Chicos como estan nuevamente algo currioso con firebird:

estoy realizando un procedimiento que actualiza campos directamente con firebird

Código SQL [-]
CREATE PROCEDURE ACTUALIZAPRECIO(
  ID_ARTCOMPRA INTEGER,
  NEW_COMPRA DECIMAL(5, 2))
RETURNS(
  IDPRECIO INTEGER,
  IDART INTEGER,
  IDARTXIVA INTEGER,
  COMISION DECIMAL(12, 2),
  GASTOS DECIMAL(12, 2),
  MARGEN DECIMAL(12, 2),
  MARGENDETALLE DECIMAL(12, 2),
  PCOMPRAPRODUCTO DECIMAL(12, 2),
  MONTOIMPUESTO DECIMAL(12, 2),
  PRECIOCIV DECIMAL(12, 2),
  PRECIOSIV DECIMAL(12, 2))
AS
DECLARE VARIABLE IDPRECIOCOMPRA INTEGER;
DECLARE VARIABLE IDARCOMPRA INTEGER;
DECLARE VARIABLE IDARTXIMPUESTO INTEGER;
DECLARE VARIABLE COMISIONCOMPRA DECIMAL(12, 2);
DECLARE VARIABLE GASTOCOMPRA DECIMAL(12, 2);
DECLARE VARIABLE MARGENCOMPRA DECIMAL(12, 2);
DECLARE VARIABLE MARGENDETALLECOMPRA DECIMAL(12, 2);
DECLARE VARIABLE NEWPCOMPRA DECIMAL(12, 2);
DECLARE VARIABLE MONTOIVA DECIMAL(12, 2);
DECLARE VARIABLE NEW_PRECIOCIV DECIMAL(12, 2);
DECLARE VARIABLE NEW_PRECIOSIV DECIMAL(12, 2);
DECLARE VARIABLE OLDPCOMPRA DECIMAL(12, 2);
DECLARE VARIABLE IDIMPUESTO INTEGER;
DECLARE VARIABLE PORCENTAJEIVA DECIMAL(3, 2);
BEGIN
 FOR 
      SELECT 
         PRECIO.ID_PRECIO,
         PRECIO.ID_ARTICULO,
          PRECIO.ID_ARTXIMPUES,
         PRECIO.COEF_COMISION,
          PRECIO.COEF_GASTOS,
          precio.COEF_MARGEN,
          precio.COEF_MARGENDETALLE,
          precio.PRECIOCOMPRA,
          PRECIO.MONTO_IMPUESTO,
          PRECIO.PRECIO_CIV,
          PRECIO.PRECIO_SIV
            FROM
             PRECIO where precio.ID_ARTICULO = :ID_ARTCOMPRA
         INTO
         :IDPRECIO,
         :IDART,
         :IDARTXIVA,
         :COMISION,
         :GASTOS,
         :MARGEN,
         :MARGENDETALLE,
         :PCOMPRAPRODUCTO,
         :MONTOIMPUESTO,
         :PRECIOCIV,
         :PRECIOSIV  
                    
 DO

 BEGIN
  SELECT
  ARTXIMPUES.ID_IMPUESTO, IMPUESTO.PORCENTAJE
   FROM ARTXIMPUES, IMPUESTO 
   WHERE IMPUESTO.ID_IMPUESTO = ARTXIMPUES.ID_IMPUESTO AND
   ARTXIMPUES.ID_ARTXIMPUES = :IDARTXIVA 
   INTO :IDIMPUESTO, :PORCENTAJEIVA;
 
    COMISIONCOMPRA = 0.00;--aquí es donde tengo el problema que me envia: scale must be between zero and precision
    GASTOCOMPRA = 0.00;
    MARGENCOMPRA = 0.00;
    MARGENDETALLECOMPRA = 0.00;

  IF (PCOMPRAPRODUCTO < NEW_COMPRA) THEN
  BEGIN
    COMISIONCOMPRA = (NEW_COMPRA * COMISION)/100;
    GASTOCOMPRA = (NEW_COMPRA * GASTOS)/100;
    MARGENCOMPRA = (NEW_COMPRA * MARGEN)/100;
    MARGENDETALLECOMPRA = (NEW_COMPRA * MARGENDETALLE)/100;
  END  

 /* UPDATE 
  PRECIO  
  SET 
  PRECIOCOMPRA = :NEWPCOMPRA,
  PRECIO_CIV = :PRECIO_CIV,
  PRECIO_SIV = :PRECIO_SIV,
  MONTOSUMAFIJA = :MONTOSUMAFIJA,
  MONTO_IMPUESTO = :MONTO_IMPUESTO,
  COEF_COMISION = :COEF_COMISION,
  COEF_GASTOS = :COEF_GASTOS,
  COEF_MARGEN = :COEF_MARGEN,
  COEF_MARGENDETALLE = :COEF_MARGENDETALLE
 
WHERE 
  ID_PRECIO = :ID_PRECIO */
  
   

 END
SUSPEND; 
END;

en fin como mencione en el código con un comentario me manda ese error.


Saludos
Responder Con Cita
  #2  
Antiguo 06-08-2015
Avatar de Casimiro Notevi
Casimiro Notevi Casimiro Notevi is offline
Moderador
 
Registrado: sep 2004
Ubicación: En algún lugar.
Posts: 32.022
Poder: 10
Casimiro Notevi Tiene un aura espectacularCasimiro Notevi Tiene un aura espectacular
A ver si te sirve:
Cita:
SCALED DATATYPES

Purpose
Use a scaled datatype to hold numbers with fixed size fractions.
Syntax
<scaled_type> ::=
{DECIMAL | NUMERIC} [(precision [, scale])]



Semantics
Firebird supports two scaled datatypes, NUMERIC and DECIMAL, for handling numeric data with a fixed decimal point, such as monetary values. You can specify optional precision and scale factors for both datatypes:
  • Precision is the total number or maximum number of digits, both significant and fractional, that can appear in a column of these datatypes. The allowable range for precision is from 1 to a maximum of 18.
  • Scale is the number of digits to the right of the decimal point that comprise the fractional portion of the number. The allowable range for scale is from zero to precision; in other words, scale must be less than or equal to precision.
NUMERIC and DECIMAL differ subtly in the way they handle numbers larger than the specified size. NUMERIC defines a datatype that holds a maximum of precision digits, whereas DECIMAL defines a datatype that holds at least that number of digits, and possibly more.
You can specify NUMERIC and DECIMAL datatypes without precision, in which case they are identical to INTEGER. The default value for scale is zero.
The below example declares a variable of type NUMERIC:
DECLARE a NUMERIC(5,3);



See also
INTEGER DATATYPE, FLOAT DATATYPE
Responder Con Cita
  #3  
Antiguo 06-08-2015
novato_erick novato_erick is offline
Miembro
 
Registrado: ago 2010
Ubicación: Panamá
Posts: 396
Poder: 14
novato_erick Va por buen camino
La teoria dice:

Cita:
Firebird es compatible con dos tipos de datos a escala, numeric y decimal, para el manejo de datos numéricos con un punto decimal fijo, como los valores monetarios

[color=#004465][font=Arial, sans-serif]

ok entiendo eso ya que lo encontre directamente aquí: http://www.janus-software.com/fbmanu...=psql&topic=30

sin embargo al hacer esto:
Código SQL [-]
IF (PCOMPRAPRODUCTO < NEW_COMPRA) THEN
  BEGIN     
      COMISIONCOMPRA = (NEW_COMPRA * COMISION)/100;  
      GASTOCOMPRA  = (NEW_COMPRA + COMISIONCOMPRA) * GASTOS /100;
      MARGENCOMPRA = (NEW_COMPRA + GASTOCOMPRA + MARGENCOMPRA)* MARGEN /100; 
      PVENTASINIVA = (COMISIONCOMPRA + GASTOCOMPRA + MARGENCOMPRA);
      SUBTOTALVENTA = NEW_COMPRA + PVENTASINIVA; 
      MONTOIVA = (SUBTOTALVENTA * PORCENTAJEIVA)/100;  
      PRECIOVENTACONIVA =  MONTOIVA + SUBTOTALVENTA; 

         UPDATE  PRECIO SET  PRECIOCOMPRA = :NEW_COMPRA,
                                       PRECIO_CIV = :PRECIOVENTACONIVA, --el valor que trae es null     
                                       PRECIO_SIV = :SUBTOTALVENTA,
                                       MONTO_IMPUESTO = :MONTOIVA
                               WHERE 
                               ID_PRECIO = :IDPRECIO;

Saludos
Responder Con Cita
  #4  
Antiguo 06-08-2015
Avatar de Casimiro Notevi
Casimiro Notevi Casimiro Notevi is offline
Moderador
 
Registrado: sep 2004
Ubicación: En algún lugar.
Posts: 32.022
Poder: 10
Casimiro Notevi Tiene un aura espectacularCasimiro Notevi Tiene un aura espectacular
No lo he mirado a fondo, apenas un vistazo, pero cambia el decimal por numeric en todos.
Responder Con Cita
  #5  
Antiguo 06-08-2015
novato_erick novato_erick is offline
Miembro
 
Registrado: ago 2010
Ubicación: Panamá
Posts: 396
Poder: 14
novato_erick Va por buen camino
Sip ya lo habia hecho en todo y nada aun me da el error


Saludos casimiro y disculpa la molestia..


novato_erick
Responder Con Cita
  #6  
Antiguo 06-08-2015
Avatar de Casimiro Notevi
Casimiro Notevi Casimiro Notevi is offline
Moderador
 
Registrado: sep 2004
Ubicación: En algún lugar.
Posts: 32.022
Poder: 10
Casimiro Notevi Tiene un aura espectacularCasimiro Notevi Tiene un aura espectacular
Pues cambia
COMISIONCOMPRA = 0.00
por
COMISIONCOMPRA = 0
Responder Con Cita
  #7  
Antiguo 07-08-2015
novato_erick novato_erick is offline
Miembro
 
Registrado: ago 2010
Ubicación: Panamá
Posts: 396
Poder: 14
novato_erick Va por buen camino
Ok encontré el problema:

tube que declarar las variables con un valor por defecto:

Código SQL [-]
as
DECLARE VARIABLE PRECIOVENTACONIVA NUMERIC(12, 2) DEFAULT 0

Esto solucionó el problema: aunque al inicializar mis variables en 0 al principio del post no se porque no tomaban ese valor si no es que estan definido en la declaración.

Extraño

pero Casimiro Gracias por tu aporte dejo este link que me ayudó a comprender cuando usar numeric y decimal:

https://firebird21.wordpress.com/201...ric-y-decimal/


Saludos a todos;
Responder Con Cita
  #8  
Antiguo 07-08-2015
novato_erick novato_erick is offline
Miembro
 
Registrado: ago 2010
Ubicación: Panamá
Posts: 396
Poder: 14
novato_erick Va por buen camino
casimiro no habia visto tu post anterior jajajajaja


pero nuevamente Gracias amigo


Saludos
Responder Con Cita
  #9  
Antiguo 07-08-2015
Avatar de Casimiro Notevi
Casimiro Notevi Casimiro Notevi is offline
Moderador
 
Registrado: sep 2004
Ubicación: En algún lugar.
Posts: 32.022
Poder: 10
Casimiro Notevi Tiene un aura espectacularCasimiro Notevi Tiene un aura espectacular
Para hacer cálculos deberías usar double, independientemente que luego lo guardes en un campo numeric.
Responder Con Cita
  #10  
Antiguo 07-08-2015
novato_erick novato_erick is offline
Miembro
 
Registrado: ago 2010
Ubicación: Panamá
Posts: 396
Poder: 14
novato_erick Va por buen camino
Te refieres a DOUBLE PRECISION en Firebird directamente?

porque en Delphi si mis variables son double.

Saludos
Responder Con Cita
  #11  
Antiguo 07-08-2015
Avatar de Casimiro Notevi
Casimiro Notevi Casimiro Notevi is offline
Moderador
 
Registrado: sep 2004
Ubicación: En algún lugar.
Posts: 32.022
Poder: 10
Casimiro Notevi Tiene un aura espectacularCasimiro Notevi Tiene un aura espectacular
Sí, claro, en firebird.
Que uses numeric(15,2) por ejemplo, si vas a guardar importes con 2 decimales, pero eso es la definición del campo.
Para hacer cálculos y no perder decimales, usa double precision.
Responder Con Cita
  #12  
Antiguo 07-08-2015
orodriguezca orodriguezca is offline
Miembro
 
Registrado: ene 2009
Posts: 221
Poder: 16
orodriguezca Va por buen camino
Volviendo al problema original quizas el punto decimal no sea punto sino coma, no más digo no.

Código SQL [-]
   COMISIONCOMPRA = 0,00;
Responder Con Cita
  #13  
Antiguo 07-08-2015
Avatar de Casimiro Notevi
Casimiro Notevi Casimiro Notevi is offline
Moderador
 
Registrado: sep 2004
Ubicación: En algún lugar.
Posts: 32.022
Poder: 10
Casimiro Notevi Tiene un aura espectacularCasimiro Notevi Tiene un aura espectacular
Eso también
Responder Con Cita
Respuesta


Herramientas Buscar en Tema
Buscar en Tema:

Búsqueda Avanzada
Desplegado

Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
No se puede convertir variable de tipo null a tipo integer. JairoC Varios 5 30-11-2011 16:43:11
Error en tipo de variable astut Internet 6 25-02-2007 17:13:45
Como pasar la parte decimal de una variable maravert Varios 1 30-10-2006 21:30:11
Vble. tipo decimal silviodp Varios 2 11-05-2004 07:10:56
obtener el error que me envia SQL server jac000y MS SQL Server 2 12-01-2004 21:47:00


La franja horaria es GMT +2. Ahora son las 12:43:42.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi