If you use MS SQL Server, you can use
STRING_SPLIT (Transact-SQL) - SQL Server | Microsoft Docs[
^]
MSDN wrote:
As an example, the following SELECT statement uses the space character as the separator:
SELECT value FROM STRING_SPLIT('Lorem ipsum dolor sit amet.', ' ');
In a practice run, the preceding SELECT returned following result table:
value
------
Lorem
ipsum
dolor
sit
amet
.
Then you can join data, like this:
SELECT ID, StockName, SectorID
FROM StockDetails
JOIN STRING_SPLIT(@SectorID,',')
ON value = SectorID;
As an alternative, you can use
CTE[
^] or
custom function[
^] to split string into parts.
Good luck