I need to check string2 if there are words that I already have in string1 and remove those.
declare @Text1 nvarchar(500) = 'apple, orange, pear'
declare @Text2 nvarchar(500) = 'banana, apple'
The output should be 'banana'
Edit: I just realized I made the question not properly. So, this is right:
DECLARE @Tab TABLE (Ingredients nvarchar(500))
insert @Tab select 'apple, orange, pear'
insert @Tab select 'banana, apple'
insert @Tab select 'pear, mango'
declare @Ingredients nvarchar(4000) = ''
select @Ingredients = @Ingredients + value + ',' from @Tab cross apply STRING_SPLIT(Ingredients, ',')
SELECT @Ingredients
current result: apple,orange,pear,banana,apple,pear,mango,
expected result: apple,orange,pear,banana,mango,