Ver Mensaje Individual
  #3 (permalink)  
Antiguo 22/08/2013, 11:06
estlui
 
Fecha de Ingreso: noviembre-2003
Mensajes: 209
Antigüedad: 21 años
Puntos: 0
Respuesta: Select case + count + 2 consultas

Excelente amigo Libras!, Eres un Master....

Quedo asi:

Código SQL:
Ver original
  1. IF (SELECT     COUNT(*) AS Expr1
  2. FROM         [tbl_forecast ]
  3. WHERE     (cuenta = 2000) AND (departamento = 65011) AND (anio = 2013)) = 1
  4. BEGIN
  5. SELECT     'Forecast:' AS Expr1, enero, febrero, marzo, abril, mayo, junio, julio, agosto, septiembre, octubre, noviembre, diciembre
  6. FROM         [tbl_forecast ]
  7. WHERE     (cuenta = 2000) AND (departamento = 65011) AND (anio = 2013)
  8. UNION ALL
  9. SELECT     'PRQs:' AS Expr1, '0' AS Expr2, '0' AS Expr3, '0' AS Expr4, '0' AS Expr5, '0' AS Expr6, '0' AS Expr7, '0' AS Expr8, '0' AS Expr9, '0'
  10.                       AS Expr10, '0' AS Expr11, '0' AS Expr12, '0' AS Expr13
  11. UNION ALL
  12. SELECT     'Saldo:' AS Expr1, '0' AS Expr2, '0' AS Expr3, '0' AS Expr4, '0' AS Expr5, '0' AS Expr6, '0' AS Expr7, '0' AS Expr8, '0' AS Expr9, '0'
  13.                       AS Expr10, '0' AS Expr11, '0' AS Expr12, '0' AS Expr13
  14. FROM         [tbl_forecast ]
  15. WHERE     (cuenta = 2000) AND (departamento = 65013) AND (anio = 2013)
  16. END
  17. ELSE
  18. BEGIN
  19. SELECT
  20. 'Forecast:' AS Expr1, '0' AS Expr2, '0' AS Expr3, '0' AS Expr4, '0' AS Expr5, '0' AS Expr6, '0' AS Expr7, '0' AS Expr8, '0' AS Expr9, '0'
  21.                       AS Expr10, '0' AS Expr11, '0' AS Expr12, '0' AS Expr13
  22.                       UNION ALL
  23.                       SELECT     'PRQs:' AS Expr1, '0' AS Expr2, '0' AS Expr3, '0' AS Expr4, '0' AS Expr5, '0' AS Expr6, '0' AS Expr7, '0' AS Expr8, '0' AS Expr9, '0'
  24.                       AS Expr10, '0' AS Expr11, '0' AS Expr12, '0' AS Expr13
  25. UNION ALL
  26. SELECT     'Saldo:' AS Expr1, '0' AS Expr2, '0' AS Expr3, '0' AS Expr4, '0' AS Expr5, '0' AS Expr6, '0' AS Expr7, '0' AS Expr8, '0' AS Expr9, '0'
  27.                       AS Expr10, '0' AS Expr11, '0' AS Expr12, '0' AS Expr13
  28.  
  29. END

Muchas gracias.

PD. aun te debo las frias.... no creas que se me ha olvidado.