Ver Mensaje Individual
  #2 (permalink)  
Antiguo 11/05/2011, 07:28
Avatar de Libras
Libras
Colaborador
 
Fecha de Ingreso: agosto-2006
Ubicación: En la hermosa perla de occidente
Mensajes: 7.412
Antigüedad: 17 años, 8 meses
Puntos: 774
Respuesta: Duda con el if y el case


SELECT TOP (100) PERCENT dbo.ReporteCualitativo.Fecha, dbo.PisosVenta.IdDivision, dbo.ReporteCualitativoDetalle.IdPlantilla,
COUNT(dbo.PisosVenta.IdUnidad) AS Unidades, dbo.Plantilla.Nombre, SUM(dbo.ReporteCualitativoDetalle.Saldo) AS Saldo,
case
when
COUNT(dbo.ReporteCualitativoDetalle.Saldo)=1
then COUNT(DISTINCT dbo.ReporteCualitativoDetalle.Saldo) else COUNT(DISTINCT dbo.ReporteCualitativoDetalle.Saldo)-1 end
AS Existe FROM dbo.Plantilla INNER JOIN
dbo.ReporteCualitativoDetalle ON dbo.Plantilla.IdPlantilla = dbo.ReporteCualitativoDetalle.IdPlantilla INNER JOIN
dbo.ReporteCualitativo ON dbo.ReporteCualitativoDetalle.IdPiso = dbo.ReporteCualitativo.IdPiso INNER JOIN
dbo.PisosVenta ON dbo.ReporteCualitativoDetalle.IdPiso = dbo.PisosVenta.IdPiso WHERE (dbo.PisosVenta.Abierta = 1)AND (dbo.PisosVenta.IdDivision = @IdUC)AND (dbo.ReporteCualitativo.Fecha=@Fecha) GROUP BY dbo.ReporteCualitativo.Fecha, dbo.PisosVenta.IdDivision, dbo.Plantilla.Nombre, dbo.ReporteCualitativoDetalle.IdPlantilla,
dbo.PisosVenta.Abierta HAVING (COUNT(dbo.ReporteCualitativoDetalle.Saldo) > 0) ORDER BY dbo.ReporteCualitativo.Fecha, dbo.PisosVenta.IdDivision, dbo.ReporteCualitativoDetalle.IdPlantilla


Saludos!!!
__________________
What does an execution plan say to t-sql query? Go f**k yourself, if you are not happy with me