title: How to Replace Nulls in PIVOT in SQL
body: <p>I have the following code and I am trying to replace the Null that appear when using the pivot with zero. I do the following but it says that "Incorrect syntax near 'ISNULL'." I am not sure what I am doing wrong? Any suggestions please</p>
  
  <pre><code>select *
  from #tempfinaltable
  pivot ISNULL(sum(TotalXSAAL),0) for Section_desc in
  ([Communication],[Construction],[Energy],[Financial Institutions],
   [General Property],[HIGHER ED &amp; HEALTHCARE],
   [Inland Marine],[Real Estate])) AS AALs
  </code></pre>
  
  <p>The same the dyanmic SQL I am using. The above query is just shows the names so you can see what I am working with  </p>
  
  <pre><code> select *
  from #tempfinaltable
  pivot (sum(TotalXSAAL) for Section_desc in
  ' + '('+@BranchNames++')) AS AALs'
  </code></pre>
  
  <p>Can you tell me what's wrong with this statement. i am having a syntax issue:  </p>
  
  <pre><code>BEGIN 
  
      Set @ISNullBranchNames = @ISNullBranchNames + 'ISNULL('+(@BranchNames+',0),' 
      Set @BranchNames = @BranchNames + '['+@BranchName+'],'
  
      FETCH NEXT FROM CUR1 INTO @BranchName
  
  END
  </code></pre>