Me podrian ayudar con esta consulta:
Código SQL:
Ver original
SELECT CASE WHEN COUNT(*) = 0 THEN (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' AS Expr10, '0' AS Expr11, '0' AS Expr12, '0' AS Expr13 UNION ALL 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' AS Expr10, '0' AS Expr11, '0' AS Expr12, '0' AS Expr13 UNION ALL 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' AS Expr10, '0' AS Expr11, '0' AS Expr12, '0' AS Expr13) ELSE (SELECT 'Forecast:' AS Expr1, enero, febrero, marzo, abril, mayo, junio, julio, agosto, septiembre, octubre, noviembre, diciembre FROM [tbl_forecast ] WHERE (cuenta = 2000) AND (departamento = 65013) AND (anio = 2013) UNION ALL 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' AS Expr10, '0' AS Expr11, '0' AS Expr12, '0' AS Expr13 UNION ALL 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' AS Expr10, '0' AS Expr11, '0' AS Expr12, '0' AS Expr13) END FROM [tbl_forecast ] 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