• I suppose the frontend in question has some minimal checks in place so that it always passes a string with even number of quotes and no repeating blanks.

    declare @s-2 varchar(8000) ='MELON '' ORANGE LEMON '' BANANA APPLE '' PEACH PEAR '' ';

    with terms as (

    select replicate('(',1-ItemNumber%2)

    + replace (rtrim(ltrim(item))

    , ' '

    , case ItemNumber%2 when 1 then' OR ' else ' AND ' end)

    + replicate(')',1-ItemNumber%2) as elem

    from dbo.DelimitedSplit8K(@s,'''')

    where len(rtrim(ltrim(item))) > 0

    )

    select stuff((select ' OR '+ elem

    from terms

    for xml path('')),1,4,'');

    See DelimitedSplit8K[/url]