title: SQL-Calculate price for how long one used an item- monthly price, weekly price, and hourly price
body: <p>let's say we are renting out a bike. There's a monthly($100), weekly($10), and hourly($1) price. If I used it for 1 month, 2 weeks, and 4 hours, the price would be $124. I have a while loop that will do the modulus to see if the hours is longer than monthly and weekly and add to the price and subtract the duration of the borrowed item.</p>
  
  <pre><code>SET @dateDiff =   DATEDIFF(hour,@TimeIn,@TimeOut); 
  -- 7 days is 168 hours
  -- 30 days is 720 hour
  
  WHILE  @bool != 1  
      BEGIN  
  
      IF (@dateDiff &gt; 720)
          SET  @totalPrice += (@dateDiff%720) * @monthlyPrice
          SET @dateDiff = @dateDiff - (@dateDiff%720)
      ELSE IF  (@dateDiff &gt; 168)
          SET  @totalPrice += (@dateDiff%168) * @weeklyPrice
          SET @dateDiff = @dateDiff - (@dateDiff%168)
      ELSE
          SET  @totalPrice += @dateDiff * @weeklyPrice
          SET @bool = 1;
  END  
  </code></pre>
  
  <p>I want to do something like above.</p>