Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > Conexión con bases de datos
Registrarse FAQ Miembros Calendario Guía de estilo Buscar Temas de Hoy Marcar Foros Como Leídos

Conexión con bases de datos

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 09-03-2005
Avatar de gluglu
[gluglu] gluglu is offline
Miembro Premium
 
Registrado: sep 2004
Ubicación: Málaga - España
Posts: 1.455
Poder: 21
gluglu Va por buen camino
Error en Stored Procedure en InterBase

Hola Amigos,

Tengo el siguiente 'Stored Procedure':
Código SQL [-]
CREATE PROCEDURE RATES_AMOUNTS_DESCRIPTION
  (category_no DECIMAL(7), subcategory_no DECIMAL(7), object_no CHAR(6), building_no DECIMAL(6))
RETURNS
  (NAME_SP VARCHAR(40))
AS
BEGIN
  If (bject_no <> '') THEN FOR Select NAME from OBJECTS where OBJECTNO = bject_no and BUILDINGNO = :building_no INTO NAME_SP DO SUSPEND;
  If (:category_no <> 0 and :subcategory_no <> 0) THEN FOR Select NAME from CATEGORIES where CATEGORYNO = :category_no and SUBCATEGORYNO = :subcategory_no INTO NAME_SP DO SUSPEND;
  If (:category_no <> 0 and :subcategory_no = 0)  THEN FOR Select NAME from CATEGORIES where CATEGORYNO = :category_no and SUBCATEGORYNO = 0 INTO NAME_SP DO SUSPEND;
END;
Me dá un error si ninguno de los 'Select' encuentra un registro apropiado y guarda su valor en NAME_SP. Llamo a este procedimiento desde un Select de un DBGrid, y si abro el Form y no encuentra ningún registro en el Select del Stored Procedure me da un error y no se abre el Form.

Lo que me gustaría es que devolviera '? ? ? ? ?' en NAME_SP si ninguno de los Select encuentra nada.

Algo así como:
Código SQL [-]
CREATE PROCEDURE RATES_AMOUNTS_DESCRIPTION
  (category_no DECIMAL(7), subcategory_no DECIMAL(7), object_no CHAR(6), building_no DECIMAL(6))
RETURNS
  (NAME_SP VARCHAR(40))
AS
BEGIN
  .....
  .....
  If (:category_no <> 0 and :subcategory_no = 0)  THEN FOR Select NAME from CATEGORIES where CATEGORYNO = :category_no and SUBCATEGORYNO = 0 INTO NAME_SP DO
  BEGIN
    If (NAME_SP IS NULL) THEN NAME_SP = '? ? ? ? ?';
    SUSPEND;
  END
END;
pero este procedimiento no funciona correctamente. Algo debo de estar haciendo mal, claro.

Gracias por vuestra ayuda.
Responder Con Cita
  #2  
Antiguo 09-03-2005
AngelMarvin AngelMarvin is offline
Miembro
 
Registrado: jun 2004
Ubicación: Santa Cruz de la Sierra
Posts: 42
Poder: 0
AngelMarvin Va por buen camino
Hola .

A riesgo de equivocarme, que valor quisiareas que retorne tu SP si NAME_SP es nulo?

Cita:
Código SQL [-]
If (NAME_SP IS NULL) THEN NAME_SP = '? ? ? ? ?';
Quizas tuvieras que inicializar esta variable con algún valor que te indique que no existe tal registro. Esto claro, si te sirviera de algo.

Saludos.
Responder Con Cita
  #3  
Antiguo 09-03-2005
Avatar de gluglu
[gluglu] gluglu is offline
Miembro Premium
 
Registrado: sep 2004
Ubicación: Málaga - España
Posts: 1.455
Poder: 21
gluglu Va por buen camino
Precisamente el valor que quiero que tome es '? ? ? ? ?' (Cinco interrogaciones separadas por un espacio).

Si inicializo la variable en
Código SQL [-]
BEGIN
  NAME_SP = '? ? ? ? ?';
  .....
  .....
no me funciona correctamente ya que al parecer el 'Select' a continuación si no encuentra nada dá el valor 'Null' a NAME_SP, por lo que entiendo que la comprobación de si el valor es nulo debe de ser después del Select.

Esa es precisamente la duda que tengo y que no logro resolver.

Un saludo
Responder Con Cita
  #4  
Antiguo 15-03-2005
pijo pijo is offline
Miembro
 
Registrado: sep 2003
Ubicación: Barcelona, casi
Posts: 56
Poder: 21
pijo Va por buen camino
Hola buenas ...

... has probado a hacerlo asi?

Cita:
CREATE PROCEDURE RATES_AMOUNTS_DESCRIPTION
(category_no DECIMAL(7), subcategory_no DECIMAL(7), object_no CHAR(6), building_no DECIMAL(6))
RETURNS
(NAME_SP VARCHAR(40))
AS
declare variable todo_null as char(1);
BEGIN
TODO_NULL = 'S';
If (bject_no <> '') THEN FOR Select NAME from OBJECTS where OBJECTNO = bject_no and BUILDINGNO = :building_no INTO NAME_SP DO SUSPEND;
if rowcount <> 0 then
begin
TODO_NULL = 'N';
end
If (:category_no <> 0 and :subcategory_no <> 0) THEN FOR Select NAME from CATEGORIES where CATEGORYNO = :category_no and SUBCATEGORYNO = :subcategory_no INTO NAME_SP DO SUSPEND;
if rowcount <> 0 then
begin
TODO_NULL = 'N';
end
If (:category_no <> 0 and :subcategory_no = 0) THEN FOR Select NAME from CATEGORIES where CATEGORYNO = :category_no and SUBCATEGORYNO = 0 INTO NAME_SP DO SUSPEND;
if rowcount <> 0 then
begin
TODO_NULL = 'N';
end
if todo_null = 'S' then
begin
name_sp = '? ? ? ? ?';
suspend;
end
END;
espero que te sirva, a mi en firebird me funciona bien
ánimos
__________________
Ánimos.
Responder Con Cita
  #5  
Antiguo 15-03-2005
pijo pijo is offline
Miembro
 
Registrado: sep 2003
Ubicación: Barcelona, casi
Posts: 56
Poder: 21
pijo Va por buen camino
Perdona, me he equivocado, el ROW_COUNT se escibe asi y no como le he puesto antes ROWCOUNT. El ROW_COUNT va con guión en medio.
__________________
Ánimos.
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


La franja horaria es GMT +2. Ahora son las 17:55:15.


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