[英]While loop for selecting field names?
I have a nasty, nasty data layout that I am forced to work with. 我不得不处理一个讨厌的,讨厌的数据布局。 I finally got a working query using C# and a for loop executing the same query over and over but adjusting which fields are called, but now I am wondering if it is possible to do it with a while loop. 我终于得到了一个使用C#的工作查询,并通过for循环反复执行相同的查询,但是调整了要调用的字段,但是现在我想知道是否可以使用while循环来做到这一点。 I am getting an error, and I am not sure if it is because I am using Faircom / C-tree as the database, or if there is something wrong with my query. 我遇到错误,我不确定这是因为我使用Faircom / C树作为数据库,还是查询有问题。 I am normally a Mysql user. 我通常是Mysql用户。
the table has 20 fields I care about and want to extract into a csv list. 该表有20个我关心的字段,要提取到csv列表中。 They are codetype1-codetype20 and I want it to be something like value1, value2, value3...
where as it is now I get them all back one at a time. 它们是codetype1-codetype20,我希望它像value1, value2, value3...
类的东西value1, value2, value3...
现在我一次又把它们都找回了。 Trouble is that codetype1 is dependent on another field to determine where I go look for the info on that code, which is why the case statements. 麻烦的是codetype1依赖于另一个字段来确定我要去哪里寻找该代码的信息,这就是case语句的原因。
DROP PROCEDURE IF EXISTS proc_loop_test;
CREATE PROCEDURE proc_loop_test()
SET @index = 1;
WHILE(@index < 21) DO
SELECT Replace(Concat(To_char(apptid), To_char(.@index) ), ' ', '') AS reference_id,
apptid AS a_reference_id,
CASE
WHEN c.ee > 0 THEN d.amt
ELSE insfee.amt
END AS amount,
CASE
WHEN c.ee > 0 THEN Rtrim(e.moneyname)
ELSE insname.namefeecatid
END AS moneyschedule_name,
CASE codetype@index
WHEN 1 THEN rtrim(a.descript)
ELSE rtrim(b.descript0)
END AS description,
CASE codetype@index
WHEN 1 THEN rtrim(a.abbrevdescript)
ELSE rtrim(b.abbrev0)
END AS abbreviated_description,
CASE codetype@index
WHEN 1 THEN rtrim(a.thiscode)
ELSE rtrim(b.thiscode0)
END AS code
FROM meetings
LEFT JOIN
(
SELECT admin.table2.procid,
admin.table2.this_code_id,
admin.v_table1.descript,
admin.v_table1.abbrevdescript,
admin.v_table1.thiscode
FROM admin.table2
INNER JOIN admin.v_table1
ON admin.table2.this_code_id = admin.v_table1.this_code_id) AS a
ON meetings.codeid@index = a.procid
LEFT JOIN
(
SELECT admin.v_table1.descript AS descript0,
admin.v_table1.abbrevdescript AS abbrev0,
admin.v_table1.thiscode AS thiscode0,
admin.v_table1.this_code_id
FROM admin.v_table1) AS b
ON meetings.codeid@index = b.this_code_id
LEFT JOIN
(
SELECT patid AS id,
ee
FROM admin.customer) AS c
ON meetings.patid = c.id
LEFT JOIN
(
SELECT this_code_id AS redid,
eecategoryid,
amt
FROM admin.eeule) AS d
ON c.ee = d.eecategoryid
AND d.redid = b.this_code_id
LEFT JOIN
(
SELECT eecategoryid AS namefeecatid,
moneyname
FROM admin.eeulenames) AS e
ON d.eecategoryid = e.namefeecatid
LEFT JOIN (SELECT pi.customer_id,
pi.primarykk_id AS picid,
pi.primarykk_name,
pi.first_name,
pi.last_name,
i.groupname,
i.ee
FROM admin.v_pir AS pi
LEFT JOIN admin.money AS i
ON pi.primarykk_id = i.insid) AS
ins
ON ins.customer_id = c.id
LEFT JOIN (SELECT this_code_id AS redid,
eecategoryid,
amt
FROM admin.eeule) AS insfee
ON ins.ee = insfee.eecategoryid
AND insfee.redid = b.this_code_id
LEFT JOIN (SELECT eecategoryid AS namefeecatid,
moneyname
FROM admin.eeulenames) AS insname
ON insfee.eecategoryid = insname.namefeecatid
WHERE codeid@index >= 1
END WHILE;
END;
I have never used a while loop, and while I understand somewhat I am supposed to select this to go INTO something, do I need to create a temp table, or can it all just be stored in memory till the end of the loop and returned. 我从来没有使用过while循环,虽然我了解了一些东西,但我应该选择它来进入某些东西,我是否需要创建一个临时表,还是可以将其全部存储到内存中直到循环结束并返回。
For what it is worth, the entire SELECT query works in C# when you replace the @index
with concatenating format " . index . "
出于其价值,当您将@index
替换为串联格式" . index . "
@index
" . index . "
时,整个SELECT查询都可以在C#中工作" . index . "
Based on the information that you have provided, it is strongly suggested that you reach out to your vendor for this. 根据您提供的信息,强烈建议您与供应商联系。 You're attempting to create a stored procedure, however, using a mySQL proprietary syntax. 但是,您正在尝试使用mySQL专有语法创建存储过程。 Stored procedure support is unique to each database vendor. 存储过程支持对于每个数据库供应商都是唯一的。 FairCom's c-treeACE SQL actually uses Java for cross platform support and .NET for Windows. FairCom的c-treeACE SQL实际上将Java用于跨平台支持,将.NET用于Windows。
https://docs.faircom.com/doc/jspt/#cover.htm https://docs.faircom.com/doc/jspt/#cover.htm
Stored procedure development requires a strong knowledge of the database layout which is highly application dependent. 存储过程的开发需要对数据库布局有深入了解,而数据库布局高度依赖于应用程序。 In this case, many legacy application dependencies may be involved. 在这种情况下,可能会涉及许多传统应用程序依赖项。 Again, your best source of information will be your application vendor. 同样,您最好的信息来源将是您的应用程序供应商。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.