title: how to use for each loop in sql server?
body: <p>I have a table <code>tblEmpDetail</code> which contains a column <code>CreatedDate</code>. </p>
  
  <p>I want to <strong>add 72 hours</strong> to each created date, so if the created date is <code>2012-07-14 07:21:19.180</code> then I want the output to be <code>2012-07-17 07:21:19.180</code>. </p>
  
  <p>Can someone let me know how can I accomplish to this?</p>
  
  <p>Actually what I want to do is to go to each row then check if the</p>
  
  <pre><code>getdate() - createddate 
  </code></pre>
  
  <p>is equal to or less than 72 hours; then I need to add 72 hours to <code>createddate</code>. Otherwise I want that column to be null. I am pasting my code that what I have done.</p>
  
  <pre><code>Declare @PassedTime datetime
  set @PassedTime= DATEDIFF(HH,Createddate, GETDATE())
  
  if CONVERT(varchar(20),@PassedTime,108)&gt;=CONVERT(varchar(20),'72:00:00',108)
  begin
      select empno,empName,CreatedDate,dateadd(HH,72,CreatedDate)BD from tblEmpDetail 
  end
  else
  begin
     select empno,empName,CreatedDate,'' as BD from tblEmpDetail
  end
  </code></pre>