Dee*_*dhy 5 coldfusion cfquery coldfusion-10
我有来自cfquery的查询结果集.我只想在特定的行号后面添加一个新的.但是每次尝试在最后插入行时都会尝试.
有什么办法可以在查询中间插入行吗?
<cfquery datasource="cse" name="abc">
select * from grade
</cfquery>
<cfset i = 0>
<cfloop query="abc">
<cfset i = i+1>
<cfif i eq 2>
<cfset queryAddRow(abc)>
</cfif>
</cfloop>
Run Code Online (Sandbox Code Playgroud)
你不能轻易做到。你有一个耦合选项。
<cfquery name="resultSet" dbtype="query">
SELECT col1, col2, etc
FROM yourQuery
WHERE [somecondition matching the "top" rows]
UNION
SELECT 'value' AS col1, 'value' AS col2, etc
UNION
SELECT col1, col2, etc
FROM yourQuery
WHERE [somecondition matching the "bottom" rows]
</cfquery>
Run Code Online (Sandbox Code Playgroud)
或者您可以简单地循环原始查询,使用和queryNew()构建新查询。在循环中的适当位置...添加要插入的行,然后继续添加其余行。queryAddRow()querySetCell()
我想不出优雅的方法。