title: How to combine two sql scripts?
body: <p>Apologies for the massively stupid question but I am curious how to get this to work.  Currently I have a query to find a number of records that I need to change based on the months difference between two dates.</p>
  
  <pre><code>SELECT [MembershipTermID]
    ,[MemberStatusProgKey]
    ,[StartDate]
    ,[EndDate]
    ,[AdditionalDiscount]
    ,[EntryDateTime]
    ,[UpdateDateTime]
    ,[MembershipID]
    ,[AgentID]
    ,[PlanVersionID]
    ,[ForceThroughReference]
    ,[IsForceThrough]
    ,[NextTermPrePaid]
    ,[IsBillingMonthly]
    ,[CICSMEMBERNUM]
    ,[CICSHISTORY]
    ,[TMPSeqNoColumn]
    ,[LastPaymentDate]
    ,[PaidToDate]
    ,[IsIndeterminate]
    ,DATEDIFF(MONTH, PaidToDate, GETDATE()) as MonthsDifference
  FROM [Apollo].[dbo].[MembershipTerm] 
  WHERE MemberStatusProgKey='DORMANT' AND IsBillingMonthly=1 AND DATEDIFF(MONTH, PaidToDate, GETDATE()) &gt; 2
  </code></pre>
  
  <p>However I found this on stackoverflow which is the correct way to pull the exact months difference between two dates:</p>
  
  <pre><code>CREATE FUNCTION FullMonthsSeparation 
  (
  @DateA DATETIME,
  @DateB DATETIME
  )
  RETURNS INT
  AS
  BEGIN
  DECLARE @Result INT
  
  DECLARE @DateX DATETIME
  DECLARE @DateY DATETIME
  
  IF(@DateA &lt; @DateB)
  BEGIN
      SET @DateX = @DateA
      SET @DateY = @DateB
  END
  ELSE
  BEGIN
      SET @DateX = @DateB
      SET @DateY = @DateA
  END
  
  SET @Result = (
                              SELECT 
                              CASE 
                                      WHEN DATEPART(DAY, @DateX) &gt; DATEPART(DAY, @DateY)
                                      THEN DATEDIFF(MONTH, @DateX, @DateY) - 1
                                      ELSE DATEDIFF(MONTH, @DateX, @DateY)
                              END
                              )
  
  RETURN @Result
  END
  GO
  </code></pre>
  
  <p>How can I combine them so I'm essentially calculating the full months difference but from the WHERE clause section?</p>