Ok,
A similar situation has been addressed on another thread, and on different sites. Select nth row on table. However, the field value I need may be a duplicate of another field.
Confusing?
which is all well and good. Except:HTML Code:SELECT TOP 1 ID_LINE AS COMMENT_5 FROM PK5.dbo.ID WHERE ID_IMKEY = @partNo AND ID_LINE not in (SELECT TOP 4 ID_LINE FROM PK5.dbo.ID WHERE ID_IMKEY = @partNo)Returns:HTML Code:SELECT * FROM PK5.dbo.ID WHERE ID_IMKEY = @partNo
Notice rows 1 and 4 are the same for the last column, the value I need. By using NOT IN (), I'm eliminating the @partNo I'm looking for, therefore the result of the querty is the fifth row. unfortunately, I don't think I can use LIN because not all ID_IMKEY contain values 1 to n (some may be deleted).HTML Code:ID_IMKEY ID_CL LIN ID_CR ID_MD ID_LINE ================================================== 1000-18006291 GEN 1 NULL NULL MUR*BLM31PG500SN1L 1000-18006291 GEN 2 NULL NULL ALI*HCB20-500 1000-18006291 GEN 3 NULL NULL MUR*BLM31PG500SN1 1000-18006291 GEN 4 NULL NULL MUR*BLM31PG500SN1L 1000-18006291 GEN 5 NULL NULL WOR*HH-1H3216-500
This is a stored procedure in SQL Server 2005.
Any help is apprectiated. On deadline, of course.
Thanks!




Reply With Quote