MATLAB Answers

Ji
1

How to specifya a sql query if the criteria is a cell array?

Asked by Ji
on 4 Feb 2014
Latest activity Answered by Sean de Wolski
on 4 Feb 2014
I've got a cell array like this sinkname = [washington newyork seattle]
and I'm connecting to a database and trying to extract the rows of data that have the exact same sinknames with the above cell array.
So I wrote the command like this: cur = exec(conn,'select city,people from map where city in sinkname');
I tried to add brackets/quotes/parenthesis around sinkname in the above command, but nothing worked.
What is the correct format of writing such query? Or is it impossible to set a where criteria like this?
My real cell array is very large so I can't type all the names in the 'where' criteria.
Thank you guys for help!

  0 Comments

Sign in to comment.

Tags

1 Answer

Answer by Sean de Wolski
on 4 Feb 2014

If you're using R2013a or newer, use strjoin to turn the cell into a string:
sinkname = {'washington' 'newyork' 'seattle'};
str = ['Select person where city in ' strjoin(sinkname)]

  0 Comments

Sign in to comment.