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 |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2006-06-05 : 09:48:44
|
| Sodi writes "Hi SQL Team, I have following records Serial#, partsname,FailDate, CAOO1, WATCH-REP1,2003-07-29 CAOO1, WATCH-REP1, 2003-08-29 CAOO1, BATTERY,2003-08-29 i want the diffrence between those two dates which having same partsname..could you please provide me the query.thanksSodi" |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-06-05 : 10:19:29
|
[code]select t1.FailDate, t2.FailDatefrom tbl t1 inner join tbl t2on t1.partsname = t2.partsnameand t1.FailDate <> t2.FailDate[/code] KH |
 |
|
|
RyanRandall
Master Smack Fu Yak Hacker
1074 Posts |
Posted - 2006-06-05 : 11:14:29
|
Just to extend what khtan has written...--datadeclare @tbl table (Serial# varchar(10), partsname varchar(20), FailDate datetime) insert @tbl select 'CAOO1', 'WATCH-REP1', '20030729'union all select 'CAOO1', 'WATCH-REP1', '20030829'union all select 'CAOO1', 'BATTERY', '20030829'--calculationselect t1.partsname, t1.FailDate, t2.FailDate, datediff(day, t1.FailDate, t2.FailDate) as DifferenceInDaysfrom @tbl t1 inner join @tbl t2on t1.partsname = t2.partsnameand t1.FailDate < t2.FailDate/*resultspartsname FailDate FailDate DifferenceInDays -------------------- ----------- ----------- ---------------- WATCH-REP1 2003-07-29 2003-08-29 31*/ Ryan Randallwww.monsoonmalabar.com London-based IT consultancy Solutions are easy. Understanding the problem, now, that's the hard part. |
 |
|
|
|
|
|
|
|