Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
jj32smith
Starting Member
7 Posts |
Posted - 2007-06-17 : 11:04:39
|
| I am new to using SQL Commands.I have a database with a table that tracks projects.I am trying to be able to compare to records in the table to get the diffdate between the two records. Ex. Table - ProjectFields -ProjectNo, SeqNo, Complete DateDataProjectNo, SeqNo, Complete Date50,1,01-01-0750,2,01-03-0750,3,01-04-07I would like to see this data returned to Query AnalyzerProjectNo, Start SeqNo, End SeqNo, Diffdatebetween 2 Dates 50,1,2,2 days50,2,3,1 dayAny help appreciated. Thanks |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-06-17 : 11:20:50
|
Try this.select s.ProjectNo, Start_SeqNo = s.SeqNo, End_SeqNo = e.SeqNo, DiffDate = datediff(day, s.CompleteDate, e.CompleteDate)from Project s inner join Project e on s.ProjectNo = e.ProjectNo and s.CompleteDate < e.CompleteDate and e.CompleteDate = (select min(CompleteDate) from Project x where x.ProjectNo = e.ProjectNo and x.CompleteDate > s.CompleteDate) KH |
 |
|
|
jj32smith
Starting Member
7 Posts |
Posted - 2007-06-18 : 22:13:31
|
| Thanks for your help. |
 |
|
|
|
|
|
|
|