Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Using a variable in sql query: WHERE, IN
Date: Sun, 9 Nov 2008 18:41:02 +0000 (UTC)
Organization: Hoodiny Entertainment
Lines: 21
Message-ID: <gf7aru$aq5$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1226256062 11077 172.30.248.37 (9 Nov 2008 18:41:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sun, 9 Nov 2008 18:41:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1446252
Xref: news.mathworks.com comp.soft-sys.matlab:499790


Hey all,

My first post here. How is everyone doing? Just want to say that this is a splendid resource for finding solutions to questions. I can't be more grateful. :) 

I have a little issue pertaining to writing the sql for the exec function in the database toolbox. Hopefully someone can help me. 

Using the Visual Query Builder, this statement works:

SELECT * FROM mytable WHERE id IN (680)

It also works from a M-file:

curs=exec(conn,'SELECT * FROM mytable WHERE id IN (680)');

Now my question is I want 680 to be a variable, eg, G, instead of a constant. Under the Database manual, 7-37 to 7-38, there is a short explanation on how to do that with the WHERE clause using square brackets and 2 pairs of quotes. 

I tried doing that with the IN operator but the M-file produces a Unexpected Matlab Expression. I figure that the pair of round brackets that guard the variable is the culprit. But not sure how so. 

Does anyone here have a solution or perhaps a suggestion? 

Thank you for reading.