February 28, 2012 at 11:42 am
Hello
Has anyone come across an answer to this.
Recordid 1 contact date 01/04/2011
Recordid 2 contact date 01/05/2011
Days between Recordid 1 contact date and recordid 2 contact date
In this case 30 days.
February 28, 2012 at 11:47 am
Steve Bramwell (2/28/2012)
HelloHas anyone come across an answer to this.
Recordid 1 contact date 01/04/2011
Recordid 2 contact date 01/05/2011
Days between Recordid 1 contact date and recordid 2 contact date
In this case 30 days.
Use this datediff function.
SELECT DATEDIFF(day, '01/04/2011'
, '01/05/2011');
February 28, 2012 at 12:06 pm
Are you looking for something like a self-join?
DECLARE @tbl TABLE
(
Recordid INT , contact_date DATE
)
INSERT INTO @tbl
VALUES (1,'20110401'),(2,'20110501');
WITH cte AS
(
SELECT *, ROW_NUMBER() OVER(ORDER BY Recordid ) row
FROM @tbl t
)
SELECT DATEDIFF(dd,cte1.contact_date,cte2.contact_date)
FROM cte cte1
INNER JOIN cte cte2
ON cte1.row = cte2.row-1
February 28, 2012 at 12:29 pm
Cheers lutz I'll give that a go. 😛
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply