I have a long sql query that I am writing in MATLAB. To make it easier for people to read what is it doing I am trying to break the query on to a few lines rather than one long line.
Below is my code (names changed).
sql_statement = strcat('select some_feilds from'...
,' databaseOne.tableOne'...
,' join databaseTwo.tableTwo'...
,' on databaseOne.tableOne.f1 = databaseTwo.tableTwo.f2'...
,' where databaseTwo.tableTwo.f2 =','''', x_lbl(1, 1),'');
The issue I have is the x_lbl(1,1) needs an ' either side of it. i.e f2 = 'Health'.
The code above gives me ''Health' which is rather fustrating as when I just the do the line below I get 'Health'. Maybe I'm going blind and losing my mind but can't see to get my query in the correct format?
lbl = strcat('''', x_lbl(1,1), '''');
update
x_lbl(1,1)
ans = 'Health Care'
sql_statement = [1x225 char]
that's the answer when using the last line,
,' where DVLP_QES.dbo.num_name_mapping.name = ','''', x_lbl(1, 1),'''');
마지막에 작은 따옴표를 2 개 더 추가해야하는 sql_statement
것처럼 완료 해야하는 경우 :select [...] tableTwo.f2 ='Health'
strcat
sql_statement = strcat('select some_feilds from'...
,' databaseOne.tableOne'...
,' join databaseTwo.tableTwo'...
,' on databaseOne.tableOne.f1 = databaseTwo.tableTwo.f2'...
,' where databaseTwo.tableTwo.f2 =','''', x_lbl(1, 1),'''');
나는 x_lbl(1, 1) = Health
따옴표없이 생각 했죠 ?
편집하다:
MATLAB R2014a 사용
>> x_lbl = 'Health';
>> x_lbl
x_lbl =
Health
>> sql_statement = strcat('select some_feilds from'...
,' databaseOne.tableOne'...
,' join databaseTwo.tableTwo'...
,' on databaseOne.tableOne.f1 = databaseTwo.tableTwo.f2'...
,' where databaseTwo.tableTwo.f2 =','''', x_lbl,'''');
>> sql_statement
sql_statement =
select some_feilds from databaseOne.tableOne join databaseTwo.tableTwo on databaseOne.tableOne.f1 = databaseTwo.tableTwo.f2 where databaseTwo.tableTwo.f2 ='Health'
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다