I have string from which I have to extract substring and query on their values.
declare @str varchar(max)
@str='Hello,world,continent,nation,city'
select * from mytable
where col_word in(SELECT REPLACE(@str,',',''','''))
The sub query
SELECT REPLACE(@str,',',''',''')
results in
Hello,'world','continent','nation','city
I want the above result be enclosed by single quotes so that it can work for IN
But this returns only for first col_word value Hello
which is first substring in @str
.
What should I do ?