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

Buenas noches...

Me podrian ayudar con esta consulta:

Código SQL:
Ver original
  1. SELECT  CASE  WHEN COUNT(*) = 0 THEN
  2.  
  3. (SELECT     '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'
  4.                       AS Expr10, '0' AS Expr11, '0' AS Expr12, '0' AS Expr13
  5.                       UNION ALL
  6.                       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'
  7.                       AS Expr10, '0' AS Expr11, '0' AS Expr12, '0' AS Expr13
  8. UNION ALL
  9. 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'
  10.                       AS Expr10, '0' AS Expr11, '0' AS Expr12, '0' AS Expr13)
  11.  
  12. ELSE
  13.  
  14. (SELECT     'Forecast:' AS Expr1, enero, febrero, marzo, abril, mayo, junio, julio, agosto, septiembre, octubre, noviembre, diciembre
  15. FROM         [tbl_forecast ]
  16. WHERE     (cuenta = 2000) AND (departamento = 65013) AND (anio = 2013)
  17. UNION ALL
  18. 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'
  19.                       AS Expr10, '0' AS Expr11, '0' AS Expr12, '0' AS Expr13
  20. UNION ALL
  21. 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'
  22.                       AS Expr10, '0' AS Expr11, '0' AS Expr12, '0' AS Expr13)
  23.                      
  24. END
  25. FROM         [tbl_forecast ]
  26. WHERE     (cuenta = 2000) AND (departamento = 65011) AND (anio = 2013)

Lo que necesito es: Si Count es = 0 entonces que ejecute una consulta.... si es igual a 1 entonces que ejecute la otra consulta....

Lo que tengo me manda un error, dice:

Msg 116, Level 16, State 1, Line 13
Only one expression can be specified in the select list when the subquery is not introduced with EXISTS.
Msg 116, Level 16, State 1, Line 25
Only one expression can be specified in the select list when the subquery is not introduced with EXISTS.

¿que me falta o que me sobra?

Mcuhas gracias