SQL query?
I have a table column with string of various length. Forexample abcd, abcde, fghijk
Now I want to get all distinct 4 long strings from this column.
Output is then:
abcd, bcde, fghi, ghij, hijk,
Thanks
SQL query?
I have a table column with string of various length. Forexample abcd, abcde, fghijk
Now I want to get all distinct 4 long strings from this column.
Output is then:
abcd, bcde, fghi, ghij, hijk,
Thanks
You can use a numbers table.
Below uses master..spt_values
for demo purposes but you should create a dedicated one instead
WITH Nums
AS (SELECT number
FROM master..spt_values
WHERE type = 'P'
AND number BETWEEN 1 AND 1000)
SELECT DISTINCT SUBSTRING(YourCol, Number, 4)
FROM (VALUES('abcd'),
('abcde'),
('fghijk'))YourTable(YourCol)
JOIN Nums N
ON Number BETWEEN 1 AND LEN(YourCol) - 3