Passing variables in query retrieves no data ...
1 view (last 30 days)
Show older comments
Why it is not displaying any data?.... When I pass number in protmass like protmass=30000 it shows output but not in this case. Thanks in advance.
Code is:
for i=1:fullindex
str = mw(i);
if isempty(str)==1
continue;
end
spot_name=spots(i);
spot_name=char(spot_name);
parts = regexp(str,'D','split');
per=parts{1}(2);
protmass=parts{1}(1); % class of protmass is cell
if strcmp(per,' Approx')
display('IN Approx')
protmass=str2double(protmass);
Upmax= num2str(protmass+900);
Upmin= num2str(protmass-900);
query=['select Sequences from Pro where MW between (',Upmin,') AND (',Upmax,')'];
curss=exec(con,query);
curss=fetch(curss);
seq=get(curss,'Data');
display(seq);
end
Output
seq =
'No Data'
5 Comments
Geoff Hayes
on 13 Sep 2015
Rafia - can you show us what value is assigned to query so that we can see how your SQL command has been constructed?
Answers (2)
the cyclist
on 12 Sep 2015
The fact that this is returning the string 'No Data' indicates that the query is syntactically valid, but is returning zero rows. [I haven't seen people use parentheses around the min/max values typically, but I verified that that works in my Postgres database.]
My best guess is that you accidentally calculated your window such that it is not capturing any values. Just as a debugging test, you could make it extremely wide. Also, might want to take the semicolon after the
query = ...
statement out, so it prints the query to the screen, to make sure it is giving what you expect.
3 Comments
the cyclist
on 13 Sep 2015
What does
query=['select Sequences from Pro where MW between (',Upmin,') AND (',Upmax,')']
output?
Have you looked at your database with some other tool to be absolutely certain there is a value in the range you are trying to extract?
All I can tell you at this stage is that I have successfully done this sort of query many times.
Geoff Hayes
on 13 Sep 2015
Rafia - I'm trying to understand your query:
select MW from Table1
You are selecting something called MW from Table1 which, according to your output, returns three fields for each record: the protmass (?), a single character, and then a string (APPROX). Is this correct, or does the query return a single string built from a number, a character, and another string?
You mention how When I pass number in protmass like protmass=30000 it shows output. Does this mean your query is something like
select MW from Table1 where protmass=30000
or is it something different? And if this query does work, then why not do something like
select MW from Table1 where protmass between (29100) and (30900)
to get the records that you desire?
See Also
Categories
Find more on Database Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!