Passing variables in query retrieves no data ...

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

koi to btaa dy :( :(........
Rafia - why are you "wrapping" the minimum and maximum values in brackets? Please write out the value of query so that we can get an idea of what the SQL statement looks like. Also, include an SQL query that does work so that we can compare the two.
Because the protmass value comes from another database. If I pass the value like protmass = 500000 it works and gives output, rest code remains same but not in this condition.
Rafia - can you show us what value is assigned to query so that we can see how your SQL command has been constructed?
sqlquery = 'select MW from Table1';
curs = exec(conn,sqlquery);
curs = fetch(curs);
mw=curs.data
Below are the few values from data base
'300000 D Approx'
'300000 D Approx'
'300000 D Approx'
'500000 D Approx'
'700000 D Approx'
'300000 D Approx'
'300000 D Approx'
'300000 D Approx'
'500000 D Approx'
'100000 D Approx'
'700000 D Approx'
After splitting only numerical value is passed in protmass

Sign in to comment.

Answers (2)

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

I tries everything but it doesnt work, even check the class.. When I pass value by myself it works not in query but in variable protmass but when it comes from file it displays no data.
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.
yup values are there in database ... it gives no data for every range

Sign in to comment.

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?

1 Comment

In every condition it will add 900 to upmax and subtract 900 in upmin... the code above shows the value of protmass comes from database... For checking If I will pass value to protmass myself it will give output but when it comes to database it gives no data for any range whether it is present in database or not..

Sign in to comment.

Asked:

on 11 Sep 2015

Commented:

on 14 Sep 2015

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!