Cómo reemplazar nulos en PIVOT en SQL
Tengo el siguiente código y estoy tratando de reemplazar el Nulo que aparece cuando se usa el pivote con cero. Hago lo siguiente pero dice que "Sintaxis incorrecta cerca de 'ISNULL'". ¿No estoy seguro de lo que estoy haciendo mal? Cualquier sugerencia por favor
select *
from #tempfinaltable
pivot ISNULL(sum(TotalXSAAL),0) for Section_desc in
([Communication],[Construction],[Energy],[Financial Institutions],
[General Property],[HIGHER ED & HEALTHCARE],
[Inland Marine],[Real Estate])) AS AALs
Lo mismo el dianmic SQL que estoy usando. La consulta anterior solo muestra los nombres para que pueda ver con qué estoy trabajando
select *
from #tempfinaltable
pivot (sum(TotalXSAAL) for Section_desc in
' + '('+@BranchNames++')) AS AALs'
¿Puedes decirme qué está mal con esta declaración? Estoy teniendo un problema de sintaxis:
BEGIN
Set @ISNullBranchNames = @ISNullBranchNames + 'ISNULL('+(@BranchNames+',0),'
Set @BranchNames = @BranchNames + '['+@BranchName+'],'
FETCH NEXT FROM CUR1 INTO @BranchName
END