SELECT ProjectID ,STRING_AGG(value, ',') WITHIN GROUP (ORDER BY value) AS NewField from ( select distinct ProjectId, newId.value FROM [dbo].[Data] WITH(NOLOCK) CROSS APPLY STRING_SPLIT([bID],';') AS newID WHERE newID.value IN ( 'O95833' , 'Q96NY7-2' ) ) x GROUP BY ProjectI...
In this query, we select the distinct hometown values from the “Hospital” table and use the STRING_AGG function to concatenate them. The DISTINCT keyword makes sure that the duplicate hometowns are removed and it results in a set of unique hometown values. Conclusion The SQL Server STRING_A...
This is an example as I do not know your schema.
Finding Duplicates with DISTINCT and HAVING Finding last occurrence of a space in a string Finding spaces in a string Finding the second space in a string First 3 columns data of a table without specifying the column names - SQL Server First and Last day of previous month from getdate() Fi...
Now the output looks like this (and you can see how applying DISTINCT or GROUP BY will eliminate the duplicates easily): (The fact the pointer always reflects thefirstinstance of the value in the original string is irrelevant, as it doesn’t really matter which unique value we get.) ...
https://github.com/orlando-colamatteo/ms-sql-server-group-concat-sqlclr
Adding the distinct before the string_agg is pointless as there is only one result. The only way I have been able to solve this for now is ( without doing a select as the join but essentially the same ) WITH cte AS (SELECT DISTINCT ...
2. Advanced Use Cases of STRING_AGG() in Postgres 2.1 Concatenating Distinct Values To prevent repeated values, you can employ DISTINCT with STRING_AGG(): Copy 1 SELECT 2 country, 3 STRING_AGG(DISTINCT email, ';') AS distinct_email_list 4 FROM 5 customer 6 GROUP BY 7 country; 2.2 ...
or add the quotes where you are preforming theDISTINCT:
from pg_locks a,pg_stat_activity b where a.mppsessionid=b.sess_idanda.granted),t_overlapas(select r.*from t_wait w join t_run ron(r.locktype is not distinct from w.locktypeandr.database is not distinct from w.databaseandr.relation is not distinct from w.relationandr.page is not...