我们可以在 QUERY-PREPARE() 中使用多个表吗?
Can we use multiple tables in QUERY-PREPARE()?
我收到了查看 QUERY-PREPARE() 的建议。我看到了一个如何使用它的示例,对其进行了调整并制作了它以便我可以使用它。一切都很好,直到我尝试将另一个 table 添加到混音中。我会把我的代码放在这里。
/* Definitions */
DEFINE VARIABLE cQuery AS CHARACTER NO-UNDO.
DEFINE VARIABLE cInString AS CHARACTER NO-UNDO.
DEFINE VARIABLE cOrStatement AS CHARACTER NO-UNDO.
DEFINE VARIABLE iEntry AS INTEGER NO-UNDO.
/* Defining a temp-table to query */
DEFINE TEMP-TABLE client
FIELD clientId AS INTEGER
FIELD city AS CHARACTER.
DEFINE TEMP-TABLE country
FIELD country AS CHARACTER
FIELD city AS CHARACTER.
/* my temp-table to test it*/
DEF TEMP-TABLE tt-cliente
FIELD id LIKE client.clientId
FIELD cidade LIKE client.city
FIELD pais LIKE country.country.
/* And a query */
DEFINE QUERY qClient FOR client,country.
/* Create some bogus data */
CREATE client.
ASSIGN
client.clientId = 1
client.city = "Rome".
CREATE client.
ASSIGN
client.clientId = 2
client.city = "Barcelona".
CREATE client.
ASSIGN
client.clientId = 3
client.city = "Paris".
CREATE client.
ASSIGN
client.clientId = 4
client.city = "Prague".
CREATE client.
ASSIGN
client.clientId = 5
client.city = "São Paulo".
CREATE client.
ASSIGN
client.clientId = 6
client.city = "Rio de Janeiro".
CREATE client.
ASSIGN
client.clientId = 7
client.city = "Brasília".
CREATE client.
ASSIGN
client.clientId = 8
client.city = "Imigrante".
/* Create some more bogus data */
CREATE country.
ASSIGN
country.country = "Italy"
country.city = "Rome".
CREATE country.
ASSIGN
country.country = "Spain"
country.city = "Barcelona".
CREATE country.
ASSIGN
country.country = "France"
country.city = "Paris".
CREATE country.
ASSIGN
country.country = "Czech Republic"
country.city = "Prague".
CREATE country.
ASSIGN
country.country = "Brazil"
country.city = "São Paulo".
CREATE country.
ASSIGN
country.country = "Argentina"
country.city = "Buenos Aires".
CREATE country.
ASSIGN
country.country = "USA"
country.city = "New York".
CREATE country.
ASSIGN
country.country = "England"
country.city = "London".
/* These are the cities we are searching for */
cInString = "1,5,8".
/* Convert the comma-separated list of cities to an "OR-statement" */
DO iEntry = 1 TO NUM-ENTRIES(cInString):
cOrStatement = cOrStatement + (IF cOrStatement = "" THEN "" ELSE " OR ") + "client.clientId = " + QUOTER(ENTRY(iEntry,cInString)).
END.
/* Add () around the or-statement just to be sure */
cOrStatement = "(" + cOrStatement + ")".
/* Put together the query */
cQuery = "FOR EACH client WHERE " + cOrStatement.
/* My edit */
cQuery = cQuery + "AND client.clientId < 6 BY client.clientId, EACH country WHERE country.city = client.city".
/* Attach the query-string to the query */
QUERY qClient:QUERY-PREPARE(cQuery).
/* Open the query ...*/
QUERY qClient:QUERY-OPEN().
/* And get the first result */
/*GET FIRST qClient. //Este aqui é o original*/
GET FIRST qClient.
/* Iterate through results as long as there are any... */
DO WHILE AVAILABLE client:
CREATE tt-cliente.
ASSIGN
tt-cliente.id = client.clientId
tt-cliente.cidade = client.city
tt-cliente.pais = country.country.
GET NEXT qClient.
END.
/* Close query */
QUERY qClient:QUERY-CLOSE().
FOR EACH tt-cliente:
DISP tt-cliente.
END.
我想创建临时文件 table,这样我就可以用 JSON 提取它。
那么有没有办法像这样做2个或更多table?谢谢?
排序 (BY) 应该在所有连接之后。然后它将起作用:
(为了便于阅读而换行
cQuery = cQuery + "AND client.clientId < 6," +
"EACH country WHERE country.city = client.city " +
"BY client.clientId".
我收到了查看 QUERY-PREPARE() 的建议。我看到了一个如何使用它的示例,对其进行了调整并制作了它以便我可以使用它。一切都很好,直到我尝试将另一个 table 添加到混音中。我会把我的代码放在这里。
/* Definitions */
DEFINE VARIABLE cQuery AS CHARACTER NO-UNDO.
DEFINE VARIABLE cInString AS CHARACTER NO-UNDO.
DEFINE VARIABLE cOrStatement AS CHARACTER NO-UNDO.
DEFINE VARIABLE iEntry AS INTEGER NO-UNDO.
/* Defining a temp-table to query */
DEFINE TEMP-TABLE client
FIELD clientId AS INTEGER
FIELD city AS CHARACTER.
DEFINE TEMP-TABLE country
FIELD country AS CHARACTER
FIELD city AS CHARACTER.
/* my temp-table to test it*/
DEF TEMP-TABLE tt-cliente
FIELD id LIKE client.clientId
FIELD cidade LIKE client.city
FIELD pais LIKE country.country.
/* And a query */
DEFINE QUERY qClient FOR client,country.
/* Create some bogus data */
CREATE client.
ASSIGN
client.clientId = 1
client.city = "Rome".
CREATE client.
ASSIGN
client.clientId = 2
client.city = "Barcelona".
CREATE client.
ASSIGN
client.clientId = 3
client.city = "Paris".
CREATE client.
ASSIGN
client.clientId = 4
client.city = "Prague".
CREATE client.
ASSIGN
client.clientId = 5
client.city = "São Paulo".
CREATE client.
ASSIGN
client.clientId = 6
client.city = "Rio de Janeiro".
CREATE client.
ASSIGN
client.clientId = 7
client.city = "Brasília".
CREATE client.
ASSIGN
client.clientId = 8
client.city = "Imigrante".
/* Create some more bogus data */
CREATE country.
ASSIGN
country.country = "Italy"
country.city = "Rome".
CREATE country.
ASSIGN
country.country = "Spain"
country.city = "Barcelona".
CREATE country.
ASSIGN
country.country = "France"
country.city = "Paris".
CREATE country.
ASSIGN
country.country = "Czech Republic"
country.city = "Prague".
CREATE country.
ASSIGN
country.country = "Brazil"
country.city = "São Paulo".
CREATE country.
ASSIGN
country.country = "Argentina"
country.city = "Buenos Aires".
CREATE country.
ASSIGN
country.country = "USA"
country.city = "New York".
CREATE country.
ASSIGN
country.country = "England"
country.city = "London".
/* These are the cities we are searching for */
cInString = "1,5,8".
/* Convert the comma-separated list of cities to an "OR-statement" */
DO iEntry = 1 TO NUM-ENTRIES(cInString):
cOrStatement = cOrStatement + (IF cOrStatement = "" THEN "" ELSE " OR ") + "client.clientId = " + QUOTER(ENTRY(iEntry,cInString)).
END.
/* Add () around the or-statement just to be sure */
cOrStatement = "(" + cOrStatement + ")".
/* Put together the query */
cQuery = "FOR EACH client WHERE " + cOrStatement.
/* My edit */
cQuery = cQuery + "AND client.clientId < 6 BY client.clientId, EACH country WHERE country.city = client.city".
/* Attach the query-string to the query */
QUERY qClient:QUERY-PREPARE(cQuery).
/* Open the query ...*/
QUERY qClient:QUERY-OPEN().
/* And get the first result */
/*GET FIRST qClient. //Este aqui é o original*/
GET FIRST qClient.
/* Iterate through results as long as there are any... */
DO WHILE AVAILABLE client:
CREATE tt-cliente.
ASSIGN
tt-cliente.id = client.clientId
tt-cliente.cidade = client.city
tt-cliente.pais = country.country.
GET NEXT qClient.
END.
/* Close query */
QUERY qClient:QUERY-CLOSE().
FOR EACH tt-cliente:
DISP tt-cliente.
END.
我想创建临时文件 table,这样我就可以用 JSON 提取它。 那么有没有办法像这样做2个或更多table?谢谢?
排序 (BY) 应该在所有连接之后。然后它将起作用:
(为了便于阅读而换行
cQuery = cQuery + "AND client.clientId < 6," +
"EACH country WHERE country.city = client.city " +
"BY client.clientId".