January 13, 2016 at 1:15 pm
Hi,
SELECT DISTINCT t1.ProjectUID,t1.BWF , t1.Deliverable ,
--Supressed data columns
STUFF(
(SELECT ', ' + (t2.[GeoMarket])
FROM #deploys t2
where t1.ProjectUID = t2.ProjectUID AND t1.BWF = t2.BWF AND t1.Deliverable = t2.Deliverable
FOR XML PATH (''))
, 1, 1, '') AS List
INTO #Projection
FROM #deploys t1
I expected values like ABC,ACG,ADG but I am getting
ABC,ABC,ABC,ACGACG,ACG,ADG ,ADG,ADG
How do I get distinct values ?
Thanks
PSB
January 13, 2016 at 1:20 pm
Did you try putting your DISTINCT on the nested SELECT?
The absence of evidence is not evidence of absence
- Martin Rees
The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
- Phil Parkin
January 13, 2016 at 1:24 pm
Can you help me with where exactly I need to place the distinct ?
January 13, 2016 at 1:27 pm
The scope of your DISTINCT is incorrect. You're enforcing a DISTINCT set of values for the outer SELECT, but at that point the concatenated list is the value of a single column.
You need to use SELECT DISTINCT at the inner query to do what you're wanting.
Cheers!
EDIT: Just noticed Phil already made this point.
January 13, 2016 at 1:31 pm
SELECT DISTINCT t1.ProjectUID,t1.BWF , t1.Deliverable ,
--Supressed data columns
STUFF(
(SELECT ', ' + (DISTINCT t2.[GeoMarket])
FROM #deploys t2
where t1.ProjectUID = t2.ProjectUID AND t1.BWF = t2.BWF AND t1.Deliverable = t2.Deliverable
FOR XML PATH (''))
, 1, 1, '') AS List
INTO #Projection
FROM #deploys t1
I get an error with this query
January 13, 2016 at 1:33 pm
Yes, that query is incorrect.
Use SELECT DISTINCT..., not SELECT ','+DISTINCT...
Cheers!
January 13, 2016 at 1:33 pm
Can you help me where exactly I need the distinct ?
January 13, 2016 at 1:36 pm
Quick untested guess
😎
SELECT DISTINCT t1.ProjectUID,t1.BWF , t1.Deliverable ,
--Supressed data columns
STUFF(
(SELECT DISTINCT ', ' + (t2.[GeoMarket])
FROM #deploys t2
where t1.ProjectUID = t2.ProjectUID AND t1.BWF = t2.BWF AND t1.Deliverable = t2.Deliverable
FOR XML PATH (''))
, 1, 1, '') AS List
INTO #Projection
FROM #deploys t1
January 13, 2016 at 1:41 pm
Thanks . 🙂
Viewing 9 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply