Hi Gordon
I think that we might be talking about two different things. If the only thing to do is to find line numbers and present them to the end user and the condition is as simple as the one presented in the post above there is certainly no need to use cursor. Take a look at this code:
SELECT N'Error in lines: ' + ( SELECT cast(a.vis AS NVARCHAR(3)) + ';' FROM ( SELECT t1.visorder + 1 'vis' FROM dbo.OINV t0 JOIN dbo.INV1 t1 ON t0.DocEntry = t1.DocEntry WHERE t1.Price < t1.GrossBuyPr AND t1.DocEntry = 18 ) a FOR XML path('') )
Since my browser refuses to cooperate when I try to insert image I don't present estimated execution plan but you can check it on your own.
Kind regards,
Radek