MATLAB: How to Build a Database query

query

Hi i have 3 variables one say Columnname tells about the database column names ,other two variable2 & variable3 tells about timestamp for eg( 03-Apr-2012 12:25:00 ).
Columnname = abcd variable2 = 03-Apr-2012 12:25:00 variable3 = 10-Apr-2012 12:25:00
after connecting to database & building query like this
data=exec(connection,'SELECT Columnname FROM TABLENMAE WHERE Columnname >= (''variable2 '') AND Columnname < (''variable3 '') ');
but i am getting data as blank.feels some issues while building query
Thanks in advance

Best Answer

Hi,
it should probably read
data=exec(connection, ['SELECT ' Columnname ' FROM TABLENMAE WHERE ' Columnname '>=("' variable2 '") AND ' Columnname ' < ("' variable3 '") ']);
Two suggestions: it's easier if you do something like
sqlstatement = ['SELECT ...' ];
data = exec(connection, sqlstatement);
because then you can put a breakpoint on the exec line and see if your sqlstatement looks fine (e.g. copy paste to database client).
Second: use querybuilder to build your sql query ...
Titus