tsql - DateDiff of Logtable Dates Which Have The Same Column in SQL Server -


using sql server 2012 need datediff of dates in log table has same column, example:

id      | version   |  status   |   date ----------------------------------------------------- 12345   |   1       |  new      |   2014-05-01 00:00:00.000 12345   |   2       |        |   2014-05-02 00:00:00.000 12345   |   3       |  appr     |   2014-05-03 00:00:00.000 67890   |   1       |  new      |   2014-05-04 00:00:00.000 67890   |   2       |        |   2014-05-08 00:00:00.000 67890   |   3       |  rej      |   2014-05-13 00:00:00.000 

i need date diff of sequential dates (date between 1, 2 , date between 2, 3)

i have tried creating while no luck!

your appreciated!

this calculates datediff per query "date diff of sequential dates",if not sequential,it show same date.further please don't use reserved keywords column names

select id, [version], [status], [date], case when lead([date]) on (partition id order [version])=dateadd(day,1,[date]) cast(datediff(day,[date],lead([date]) on (partition id order version))  varchar(5))  else [date] end datedifff #temp 

Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -