Ver Mensaje Individual
  #2 (permalink)  
Antiguo 21/01/2010, 09:27
Avatar de Andres95
Andres95
Colaborador
 
Fecha de Ingreso: diciembre-2004
Mensajes: 1.802
Antigüedad: 19 años, 4 meses
Puntos: 38
Respuesta: Error en división con ceros

Al parecer solo estaban mal los parentesis...

Adicional le agregue un isnull dentro del sum para eliminar el mensaje de warning:

-- Warning: Null value is eliminated by an aggregate or other SET operation.

Código:
IF OBJECT_ID('TEMPDB..#tmpdecimal') IS NOT NULL DROP TABLE #tmpdecimal

CREATE TABLE #tmpdecimal (montomuebles int, totalsolomuebles int )

INSERT INTO #tmpdecimal VALUES (1, 0)
INSERT INTO #tmpdecimal VALUES (2, NULL)
INSERT INTO #tmpdecimal VALUES (8, 4)
INSERT INTO #tmpdecimal VALUES (16, 8)

SELECT ISNULL(
              SUM(b.montomuebles)    
             ,0
             ) 
       / 
       NULLIF( 
              SUM(
                 ISNULL(b.totalsolomuebles,0)
                 )
             ,0
             )                   SdoPromMuebles
FROM   #tmpdecimal b
Saludos!
__________________
La sencillez y naturalidad son el supremo y último fin de la cultura...
--
MCTS : SQL Server 2008, .NET Framework 3.5, ASP.NET Applications.