• Here's another way. Just uncomment your code and comment out the sample data.

    WITH CTE (NMDOS, ETOTALDEB, tpdesc, dataobra, NOME, OBRANO, nmdoc, FNO, etiliquido)

    AS (

    --SELECT distinct BO.NMDOS,bo.ETOTALDEB, bo.tpdesc ,bo.dataobra,BO.NOME ,BO.OBRANO,ft.nmdoc,FT.FNO,CASE

    --WHEN FT.NDOC<> 1

    --THEN 0

    --ELSE FT.ETTILIQ

    --END as etiliquido

    --FROM BO left JOIN BI ON bi.bostamp=bo.bostamp left JOIN FI ON fi.bistamp=bi.bistamp

    --left JOIN FT ON FT.FTSTAMP=FI.FTSTAMP WHERE BO.ndos='18' and bo.fechada=0

    --GROUP BY BO.NMDOS,bo.DATAOBRA,BO.NOME,BO.OBRANO,BI.OBRANO,FT.FNO,FT.ETTILIQ,bo.tpdesc ,ft.nmdoc,bo.ETOTALDEB,ft.ndoc

    SELECT 'Dossier 1',1000.00,10,20130210,'client',999,'Invoice',1.150,00

    UNION ALL SELECT 'Dossier 1',1000.00,10,20130210,'client',999,'Invoice',4.250,00

    UNION ALL SELECT 'Dossier 1',1000.00,10,20130210,'client',999,'Invoice',6.250,00

    )

    SELECT NMDOS, CASE rn WHEN 1 THEN ETOTALDEB ELSE NULL END

    ,tpdesc, dataobra, NOME, OBRANO, nmdoc, FNO, etiliquido

    FROM (

    SELECT *, rn=ROW_NUMBER() OVER (PARTITION BY NMDOS ORDER BY dataobra)

    FROM CTE) a

    ORDER BY DATAOBRA


    My mantra: No loops! No CURSORs! No RBAR! Hoo-uh![/I]

    My thought question: Have you ever been told that your query runs too fast?

    My advice:
    INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
    The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.

    Need to UNPIVOT? Why not CROSS APPLY VALUES instead?[/url]
    Since random numbers are too important to be left to chance, let's generate some![/url]
    Learn to understand recursive CTEs by example.[/url]
    [url url=http://www.sqlservercentral.com/articles/St