DROP FUNCTION GetDistinct
create function GetDistinct(@str varchar(1000))
returns varchar(1000)
as
BEGIN
declare @ret varchar(8000),@return varchar(8000)
select @str = @str+','
while charindex(',',@str) > 0
begin
select @ret = substring(@str,1,charindex(',',@str)-1)
select @return = isnull(@return+',','')+@ret
select @str = replace(@str,@ret+',','')
end
RETURN @return
END
GO
select dbo.getdistinct('APR-11,APR12,APR06,APR-11,APR12,APR06')