i have a query
declare @str as varchar(MAX)= '12,145,1598,1,5';
insert into rdmapping (itemid, rdid) values((Select value From String_Split( @str, ',')),100)
and getting an error
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.

Jignesh KumarRank #91 · 22.9K reputationPosted Nov 9, 2022, 4:18 AM EST
Hi Grisma,
You are using sub query in insert statement which will return multiple row. multiple rows will not allow in single column insert due to that its throwing error,
Try this way you can achieve your stuff,
declare @str as varchar(MAX)= '12,145,1598,1,5'; insert into rdmapping (itemid, rdid) Select value as itemid, 100 as rdid From String_Split( @str, ',') select * from rdmappingGarima BansalRank #1,554 · 1K reputationPosted Nov 9, 2022, 4:53 AM EST
thanks Jignesh Kumar
this works,
but if empty string enter then what will be the condition apply
declare @str as varchar(MAX)= ' ';
insert into rdmapping (itemid, rdid)
Select value as itemid, 100 as rdid From String_Split( @str, ',')
select * from rdmapping