How can I write variable in sub query

i try to write variable in sub query like this :
exec(conn,['select course_id from course where course_id not in' (['select course_id from transcript where student_id=' '''' aa2 '''']) ]);
not respond
Thank you.

 채택된 답변

the cyclist
the cyclist 2011년 6월 17일

2 개 추천

I think the following is what you want:
>> queryText = ['select course_id from course where course_id not in (select course_id from transcript where student_id=',num2str(aa2),')'];
>> exec(conn,queryText)

댓글 수: 1

sayer ali
sayer ali 2011년 6월 17일
thank you very much the command work perfectly

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

추가 답변 (1개)

the cyclist
the cyclist 2011년 6월 16일

1 개 추천

Is aa2 a numeric variable, or a string? You might need to use the num2str() function.
I can't fully debug this right now, but in a case like this, I recommend building your string up piece by piece, outside the exec() function, to make sure the string you send as a query really looks like you expect it to. Looks to me that, for example, you do not really have the parentheses in there as part of the string, the way you want to for a subquery.

댓글 수: 1

sayer ali
sayer ali 2011년 6월 16일
aa2 is numeric ,i try the same query in ms sql it respond like this
select course_id from course where course_id not in (select course_id from transcript where student_id=7000032);
it respond
you knew when you write this query in mat lab with variable will be somehow different

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

카테고리

태그

Community Treasure Hunt

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

Start Hunting!

Translated by