Example of dateDiff

November 14th, 2007 by Mr.M | No Comments »

– requirement: get agreementVersionID where the transactiondate is within 30 days from the billingcoveragestartdate

– transactiondate = 30-06-2007 between 28-09-2007

select top 100 agreementversionid, billingcoveragestartdate, transactiondate from pansales..licensetransactionitem
where billingcoveragestartdate is not null
and transactiondate between ’06-30-2007′ and ’09-28-2007′
and datediff (d,transactiondate,billingcoveragestartdate) <= 30
order by billingcoveragestartdate desc

The key here is the dateDiff. Without it, the requirement can’t be met, then again there might be another way to go about it.

Leave a Reply

You must be logged in to post a comment.