I have a function that is designed to return a variable that contains
concatenated values from a partinular field in the returned rows:
DECLARE @output varchar(8000)
SELECT
@output =
CASE
WHEN @output IS NULL THEN CAST(TSD.ScheduledTime AS
varchar(4))
ELSE @output+ ', '+ ISNULL(CAST(TSD.ScheduledTime AS
varchar(4)),'')
END
FROM TSD
WHERE ClientGUID = 2000001447020001 AND
ParentGUID = 6000006684068001
Select @output
The variable returned with this code contains:
"1200, 1400, 1200, 1400"
I want to only get the unique values so that the variable returns "1200,
1400". Seems simple enough just to add DISTINCT to the SELECT statement.
However, what is returned is simply "1400".
I cannot figure out why that is the case. Is there any explanation to this
result?
Side note: I can work around this by using a cursor but I would like to
know why DISTINCT does not work.
Many thanks in advance for any help that can be provided!
Pat