That should do it, thanks.
"Hugo Kornelis" <hugo@perFact.REMOVETHIS.info.INVALID> wrote in message
news:63ea23hgghbct6037nnec2srvbb6fk3lpk@4ax.com...
> On Tue, 17 Apr 2007 10:04:49 +0100, Vayse wrote:
>
>>I have a Client table, with a field StartDate
>>I also have a Sales table. There is a field called SaleDate.
>>I'd like to run a query, and flag any Sales within one year of the Clients
>>start date as New Business.
>>I thought I'd just this would be easy - use DateDiff, but I was wrong!
>>
>>For example:
>>Client Start Date = 12/04/06 - 12th April 2006
>>
>>Sale Date = 04/04/06
>>DATEDIFF(m, dbo.Clients.Client_StartDate, dbo.Sales.SaleDate) = 12
>>Sale Date = 13/04/06
>>DATEDIFF(m, dbo.Clients.Client_StartDate, dbo.Sales.SaleDate) = 12
>>
>>So I get 12 months in both cases. As it states in the T-SQL help:
>>DateDiff - Returns the number of date and time boundaries crossed between
>>two specified dates.
>>
>>So what should I use instead of DateDiff?
>
> Hi Vayse,
>
> You can use the formula below to calculate the difference in "real"
> years (found on
>
http://classicasp.aspfaq.com/date-time-routines-manipulation/given-two-dates-how-do-i-determine-an-age.html)
>
> DECLARE @birthdate SMALLDATETIME, @endDate SMALLDATETIME
> SET @birthdate = '19740224'
> SET @endDate = GETDATE()
>
> SELECT DATEDIFF
> (
> YEAR,
> @birthdate,
> @endDate
> ) - CASE
> WHEN 100 * MONTH(@endDate) + DAY(@endDate)
> < 100 * MONTH(@birthdate) + DAY(@birthdate)
> THEN 1 ELSE 0 END
>
>
> --
> Hugo Kornelis, SQL Server MVP
> My SQL Server blog:
http://sqlblog.com/blogs/hugo_kornelis