I have a stored procedure in within which a column having comma separated values (codeid
) like ('20045,20069,20079') is being used for where in clause inside sub query for a main select statement. I tried some work around but couldn't find proper solution.
This is my code:
SELECT
CodeID, Name,
Experience,
(SELECT COALESCE(@CodeDescription + '', '', '''') + CAST([Description] AS varchar(100))
FROM SynCode
WHERE CodeID IN (SELECT *
FROM dbo.fnSplitString(codeid, ','))) AS [codeDescription]
FROM
Code
WHERE CodeIdentity = 1
Here SynCode
contains description for each code and dnSplitString
is a function which converts the CSV integer string into table.
While executing the above statement I'm getting the following error:
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
Any help on this would be appreciated.
Since I need only one row to return I'm using COALESCE to separate values with comma
Edit: I have
CodeID as '20045,20069,20079'
and Iam Expecinting row result as
20045,20069,20079|Marry|2 years|Finance, Retail, Sales
Edit: CodeID, Name, Experience is VARCHAR, and CodeID in SynCode is Int