Ver Mensaje Individual
  #2  
Antiguo 15-04-2011
Avatar de gluglu
[gluglu] gluglu is offline
Miembro Premium
 
Registrado: sep 2004
Ubicación: Málaga - España
Posts: 1.455
Reputación: 21
gluglu Va por buen camino
No sé si lo siguiente es correcto y si realmente es eficiente en cuanto a tiempo de ejecución frente a otras posibilidades :

Código SQL [-]
Select TA.CampoA1, TA.CampoA2,
  case when TB.Min_CampoB1 = 1 then ..... else .... end as Resultado1,
  case when TB.Min_CampoB1 = 2 then ..... else .... end as Resultado2,
  case when TB.Min_CampoB1 = 3 then ..... else .... end as Resultado3
from TABLA_A TA
left join SP_PRUEBA(TA.CLAVE1) TB
  on TA.CLAVE1 = TA.CLAVE1

... pero me permite utilizar TB.Min_CampoB1 como 'valor' en toda la consulta.

El Stored Procedure SP_PRUEBA se podría definir como :
Código SQL [-]
CREATE OR ALTER PROCEDURE SP_PRUEBA (
    in_Clave1 integer)
returns (
    Min_CampoB1 integer)
as
begin
 
  Select Min(CampoB1) from TABLA_B 
  where Clave1 = :In_Clave1
  into Min_CampoB1;
  
  suspend;

end
__________________
Piensa siempre en positivo !
Responder Con Cita