필터 지우기
필터 지우기

Matlab Database Toolbox join

조회 수: 2 (최근 30일)
Brian
Brian 2012년 4월 27일
I am wrting a SQL query to pull a list of securities from a table that I am connecting to via ODBC connection. What I'd like to do is filter this query (specifically the FundTicker field) by the list of tickers that I have in my cell variable called "Test". I am wondering if I can even do this. Will it ever see a variable as another table that I can join with? Or do I need to do something different with my variable before the "like" statement will workj. Right now my Test variable is below. Does this need to be a character variable?
Test = {'AAAGX'; 'FNEVX'};
Query SQL
e = exec(conn,'SELECT ALL MSTARFUNDID,ASOFDATE,FUNDTICKER FROM MSTAR.FUNDHEADER WHERE ASOFDATE = ''2004-12-31'' AND FUNDTICKER IN ' Test);
Thanks for the help, Brian

채택된 답변

the cyclist
the cyclist 2012년 4월 28일
I don't know of a way to access the contents of a cell array as part of a query. I had a similar issue in which I wanted to access the contents of a numerical array, but the only way I could think to do it was to construct the string:
numericArray = [1 2 3];
preliminaryString = sprintf('%d,',numericArray);
stringList = ['(',preliminaryString(1:end-1),')'];
This gives the string '(1,2,3)' as result, which I then use in my query.
I'm afraid you'll have to do the equivalent for your cell.
  댓글 수: 3
Brian
Brian 2012년 4월 30일
I tried to create the IN filter manually and am still having difficulty getting the query to accept. Would you mind assisting me with that?
Brian
Brian 2012년 5월 3일
I ended up creating a for loop but using the same ideas that you have here. I couldn't get sprintf to work proprely with text. Here is my ending code.
PGQryFilt = ['''' MonthlyPG{1} ''''];
for i = 1:length(MonthlyPG)
PGQryFilt = [PGQryFilt ', ' '''' MonthlyPG{i} ''''];
end
Thanks,
Brian

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Database Toolbox에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by