Hi, I have a Stro proc with many instructions among which this one [SQL] select cmp_id from CSR_COMPLEMENT where DOS_ID = (select DOS_ID from CSR_DOSSIER where DOS_NODE = @DOS_NODE) order by cmp_numordre[/SQL]
if the number of row is 01, i can easily get the cmp_id, now how can i get the cmp_id when the number of row is more than one? in this case the cmp_id to take is the one with the higher cmp_numordre. from the result, I writing a new sql.
select cmp_id from CSR_COMPLEMENT
where DOS_ID = (select top 1 DOS_ID from CSR_DOSSIER where
DOS_NODE = @DOS_NODE order by cmp_numordre)
order by cmp_numordre
select cmp_id from CSR_COMPLEMENT
where DOS_ID = (select top 1 DOS_ID from CSR_DOSSIER where
DOS_NODE = @DOS_NODE order by cmp_numordre desc)
order by cmp_numordre
Srinika
as definition says the cmp_id to take is the one with the higher cmp_numordre
------------------------------------------------------------------------------------------------------ SQL Server MVP http://visakhm.blogspot.com/