Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can use Following function to Split the row values by '<code>,</code>' </p> <pre><code>CREATE FUNCTION [dbo].[ConvertToTable] ( @delimiter char(1), @string nvarchar(MAX) ) RETURNS @Values TABLE ( VALUE NVARCHAR(MAX) ) AS BEGIN SET @string = @string + @delimiter ; WITH Nbrs_3 ( n ) AS ( SELECT 1 UNION SELECT 0 ) , Nbrs_2 ( n ) AS ( SELECT 1 FROM Nbrs_3 n1 CROSS JOIN Nbrs_3 n2 ) , Nbrs_1 ( n ) AS ( SELECT 1 FROM Nbrs_2 n1 CROSS JOIN Nbrs_2 n2 ) , Nbrs_0 ( n ) AS ( SELECT 1 FROM Nbrs_1 n1 CROSS JOIN Nbrs_1 n2 ) , Nbrs ( n ) AS ( SELECT 1 FROM Nbrs_0 n1 CROSS JOIN Nbrs_0 n2 ) INSERT @Values ( [VALUE] ) SELECT SUBSTRING(@string, n + 1, CHARINDEX(@delimiter, @string, n + 1) - n - 1) FROM ( SELECT 0 AS 'n' UNION ALL SELECT TOP ( LEN(@string) - 1 ) ROW_NUMBER() OVER ( ORDER BY n ) AS 'n' FROM Nbrs ) x WHERE SUBSTRING(@string, n, 1) = @delimiter OR n = 0 RETURN END </code></pre> <p>And Use following Code to Get the result..</p> <pre><code>DECLARE @unique_value NVARCHAR(MAX) WITH cte AS ( SELECT 1 AS id, 'apple,watermelon,pineaple' AS String UNION SELECT 2 ,'apple,pineaple,orange' UNION SELECT 3 ,'apple,blue berry' ) SELECT @unique_value= COALESCE(@unique_value+',','')+[VALUE] FROM [cte] CROSS APPLY [dbo].[ConvertToTable](',',[String]) AS CTT GROUP BY [VALUE] SELECT @unique_value </code></pre> <p><strong>UPDATE</strong>: I didn't notice this is about postgresql. i have gave the answer for MSSQL, If you could do the same in postgresql. this method would help you..</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload