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 |
|
dbenoit64
Starting Member
36 Posts |
Posted - 2006-07-20 : 12:40:18
|
| I've been fighting with this all day there has to be an easy way to do this in a single query:FOR EACH fac_id, get the INSPECTION_ID of the earliest start_date:INSPECTION_ID FAC_ID START_DATE300720040628004 566 2004-07-07300720030618002 566 2003-06-25200820021219011 1436 2002-12-19300720030206002 1458 2003-02-03300720030206003 1458 2003-02-05300720030121002 1480 2003-03-25300720030121003 1480 2005-02-02200820031230001 1436 2003-12-30300720040616006 1566 2004-08-26300720040616001 1566 2001-08-26300720040616005 1566 2002-08-26300720040616002 1566 2003-08-26300720040616003 1566 2004-08-26300720040616004 1566 2006-08-26300720040504004 1569 2004-09-10DESIRED OUTPUTINSPECTION_ID FAC_ID START_DATE300720030618002 566 2003-06-25200820021219011 1436 2002-12-19300720030206002 1458 2003-02-03300720030121002 1480 2003-03-25200820031230001 1436 2003-12-30300720040616001 1566 2001-08-26300720040504004 1569 2004-09-10any help would be greatly appreciated... |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2006-07-20 : 12:58:01
|
| select *from tbl twhere START_DATE = (select min(START_DATE) from tbl t2 where t2.FAC_ID = t.FAC_ID)==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
|
|
|