我有一个讨厌的,讨厌的数据布局,我被迫与之合作。我终于得到了一个使用C#的工作查询和for循环执行相同的查询,但调整了哪些字段被调用,但现在我想知道是否可以使用while循环。我收到一个错误,我不确定是不是因为我使用Faircom / C-tree作为数据库,或者我的查询有问题。我通常是一个Mysql用户。
该表有20个我关心的字段,想要提取到csv列表中。它们是codetype1-codetype20,我希望它像value1, value2, value3...
一样,现在我一次又一次地取回它们。麻烦的是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;
我从来没有使用过while循环,虽然我有点理解我应该选择这个去INTO东西,我是否需要创建一个临时表,或者它可以只存储在内存中直到结束循环并返回。
对于它的价值,当您用@index
连接格式替换" . index . "
时,整个SELECT查询都在C#中工作
答案 0 :(得分:0)
根据您提供的信息,强烈建议您与供应商联系。但是,您尝试使用mySQL专有语法创建存储过程。存储过程支持对每个数据库供应商都是唯一的。 FairCom的c-treeACE SQL实际上使用Java进行跨平台支持,使用.NET进行Windows。
https://docs.faircom.com/doc/jspt/#cover.htm
存储过程开发需要强烈的数据库布局知识,这是高度依赖于应用程序的。在这种情况下,可能涉及许多遗留应用程序依赖性。同样,您的最佳信息来源将是您的应用程序供应商。