remove duplicate items

From: Ammammata <ammammata_at_tiscalinet.it>
Date: Thu, 14 Feb 2019 09:57:31 +0000 (UTC)
Message-ID: <XnsA9F66F7DD5898ammammatatiscalineti_at_148.251.67.112>



[Quoted] this query, used in Delivery printout, scans all products in the doc and for each gets the corresponding Order number, to be printed in sorted order and separated by a slash:

select d.docnum, 'txt' Testo
into #tmp
from dln1 a
inner join dln1 b On a.U_I_BaseEntry = b.docentry And a.U_I_BaseType = 15 inner join rdr1 c On b.baseentry = c.docentry And b.BaseLine = c.linenum And b.BaseType = 17
inner join ordr d On c.docentry = d.docentry where a.docentry = '87'

Select distinct
STUFF((Select ' / '+ cast(t1.docnum as varchar(100)) from #tmp T1
where T1.Testo = T2.Testo
For XML PATH(''))

    ,1,3,'')
  from #tmp t2
  drop table #tmp

It generates the following:

6153 / 6153 / 6153 / 6153 / 6153 / 6153 / 6153 / 6153

because the delivery has 8 products, all of them from the same order

how can I reduce it to a single occurrence?

TIA

-- 
/-\ /\/\ /\/\ /-\ /\/\ /\/\ /-\ T /-\
-=- -=- -=- -=- -=- -=- -=- -=- - -=-

>>>>> http://www.bb2002.it :) <<<<<
........... [ al lavoro ] ...........
Received on Thu Feb 14 2019 - 10:57:31 CET

Original text of this message