title: SQL SERVER Replacing the null value in dynamic PIVOT
body: <p>Good day/night to all.
  I'm new in stored procedure, i have lack of experience and understanding when it comes to stored procedure. I tried the other tutorial and answers but i don't know why my query wasnt working when using isnull(payment,'0') or coalesce(payment,'0').</p>
  
  <pre><code>declare @sql as nvarchar(max) = '[2013-04-01],[2013-04-02],[2013-04-03],[2013-04-04],[2013-04-05],[2013-04-06]';
  declare @name as nvarchar(max) = 'Derichel'
  set @sql =
  'SELECT pid, [Fullname], ' + @sql + '
  FROM
  (SELECT pid, [Fullname], payment, dateregistration
  from tbl_Personal
  ) AS s
  PIVOT
  (
  min(payment)
  FOR dateregistration IN (' + @sql + ')
  ) AS pvt
  where [Fullname] = ''' + @name + '''
  order by pid'
  execute sp_executesql @sql;
  </code></pre>
  
  <p>Some answer and tutorials have fixed column inside IN ().
  My @sql has been set to different date(it depends on user input from gui).</p>
  
  <p>How can i replace the null value to 0?</p>
  
  <p>the output of above code is</p>
  
  <pre><code>pid Fullname [2013-04-01] [2013-04-02] [2013-04-03] [2013-04-04] [2013-04-05] [2013-04-06]
  
  6   Derichel     NULL         NULL          NULL         NULL        NULL           0
  </code></pre>
  
  <p>i want to replace the null to 0.</p>