Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


select distinct


select distinct

Author
Message
carlos cachulo-318532
carlos cachulo-318532
Valued Member
Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)

Group: General Forum Members
Points: 50 Visits: 143
Hello

i´ve this query

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
order by bo.DATAOBRA

--- that returns this something like this--

Dossier 1|1000,00|10|20130210|client|999|Invoice|1|150,00
Dossier 1|1000,00|10|20130210|client|999|Invoice|4|250,00
Dossier 1|1000,00|10|20130210|client|999|Invoice|6|250,00

.... and goes on...

my question ? can i remove the duplicate row value 1000,00, to return only the first, to something like this

Dossier 1|1000,00|10|20130210|client|999|Invoice|1|150,00
Dossier 1|Null|10|20130210|client|999|Invoice|4|250,00
Dossier 1|Null|10|20130210|client|999|Invoice|6|250,00

thanks in advance
Luis Cazares
Luis Cazares
SSCrazy Eights
SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)

Group: General Forum Members
Points: 8554 Visits: 18142
Without a lot of information, I guess you could do something like this.

SELECT distinct BO.NMDOS,
CASE WHEN FT.FNO = MIN(FT.FNO) OVER(PARTITION BY BO.NMDOS) THEN bo.ETOTALDEB END AS 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
order by bo.DATAOBRA




Luis C.
General Disclaimer:
Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?


How to post data/code on a forum to get the best help: Option 1 / Option 2
carlos cachulo-318532
carlos cachulo-318532
Valued Member
Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)

Group: General Forum Members
Points: 50 Visits: 143
First of all, many thanks for your response

it returned

Dossier 1|Null|10|20130210|client|999|Invoice|1|150,00
Dossier 1|Null|10|20130210|client|999|Invoice|4|250,00
Dossier 1|Null|10|20130210|client|999|Invoice|6|250,00

and i need that first value 1000,00

Dossier 1|1000,00|10|20130210|client|999|Invoice|1|150,00
Dossier 1|Null|10|20130210|client|999|Invoice|4|250,00
Dossier 1|Null|10|20130210|client|999|Invoice|6|250,00
Sean Lange
Sean Lange
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16592 Visits: 17024
Maybe this?


select NMDOS, case RowNum when 1 then ETOTALDEB else NULL end as ETOTALDEB, tpdesc, dataobra, NOME, OBRANO, nmdoc, FNO, etiliquido
from
(
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, ROW_NUMBER() over (Partition by bo.ETOTALDEB order by bo.DATAOBRA) as RowNum
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
) x
order by x.DATAOBRA



The problem here is that we are shooting in the dark. We can't see your tables, have no concept of your data or what you are trying to do. We can't test the code we post and we have no real idea if it will work.

If this doesn't do it then please take a few minutes and read the first article in my signature for best practices when posting questions.

_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
carlos cachulo-318532
carlos cachulo-318532
Valued Member
Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)

Group: General Forum Members
Points: 50 Visits: 143
it worked as i intended.

Next time i post something, i definitly will put more information ( tables, data, fields...), to help you help me!

Thank you very much for your time and patience.
dwain.c
dwain.c
SSCarpal Tunnel
SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)

Group: General Forum Members
Points: 4259 Visits: 6431
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!

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?
Since random numbers are too important to be left to chance, let's generate some!
Learn to understand recursive CTEs by example.
Splitting strings based on patterns can be fast!
My temporal SQL musings: Calendar Tables, an Easter SQL, Time Slots and Self-maintaining, Contiguous Effective Dates in Temporal Tables
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search