title: SQL figuring out days remaining based on days interval (using SQL Server 2005)?
body: <p>I have a table that represents a user's subscription to our system. I have two tables. One represents the subscription for an account and the other represents the type of subscription. The subscription table relates to the subscription type table with a subscriptionTypeID field in the subscription types table. I need to figure out the days remaining for that account. Here is my example:</p>
  
  <p>The user signed up on January 1, 2010 and their term is 30 days. Based on today's date (January 25, 2010) they would have 6 days remaining. </p>
  
  <p>I need help designing the SQL. Here is what I have so far in my stored procedure:</p>
  
  <pre><code>@SubscriptionTypesID int
  
  Declare @term int
  Declare remainder int
  Set @term = (SELECT subscriptionTerm 
           FROM dbo.SubscriptionTypes 
           where dbo.SubscriptionTypes.SubscriptionTypesID = @SubscriptionTypesID)
  </code></pre>
  
  <p>Now i need to figure out what to do with the remainder query, or if I can somehow have one SQL statement so I don't have to get the term separately.</p>
  
  <p>Update:</p>
  
  <p>Here is what I got now with all your help, but I still want a more elgant way to pump the term field value into the query:</p>
  
  <pre><code>Select (DateDiff(day,getDate(),DATEADD (day , 30, '01/01/2010' ))) days
  </code></pre>
  
  <p>Update 2.0 ;)</p>
  
  <p>Sometimes the answer is right in front of me and I can't even see it. I tend to over think problems and make them more complicated than they need to be. Thanks to everyone who helped! HEre is the code:</p>
  
  <pre><code>SELECT (DateDiff(day,getDate(),DATEADD (day , subscriptionTerm, dbo.Subscriptions.subscriptionDate ))) days
  FROM
    dbo.Subscriptions
    INNER JOIN dbo.SubscriptionTypes ON (dbo.Subscriptions.subscriptionTypeID = dbo.SubscriptionTypes.SubscriptionTypesID)
  WHERE
    dbo.Subscriptions.userID = 129
  </code></pre>