如何将 QueryAddRow() 添加的行作为查询结果的第一行?
我正在输出一个查询,但需要指定结果的第一行。我使用 QueryAddRow() 添加行并使用 QuerySetCell() 设置值。 我可以很好地创建行,我可以很好地将内容添加到该行。如果我将行号的参数保留在 QuerySetCell() 之外,那么它在输出时作为查询的最后结果都可以很好地工作。但是,我需要它作为查询的第一行,但是当我尝试使用 QuerySetCell 设置行属性时,它只会覆盖查询中返回的第一行(即我的 QueryAddRow() 替换查询中的第一条记录)。我目前所拥有的是从 recordCount 设置一个变量并安排输出,但必须有一种非常简单的方法来做到这一点,但我只是没有得到。 此代码将行值设置为 1,但会覆盖查询中返回的第一个行。
<cfquery name="qxLookup" datasource="#application.datasource#">
SELECT xID, xName, execution
FROM table
</cfquery>
<cfset QueryAddRow(qxLookup)/>
<cfset QuerySetCell(qxLookup, "xID","0",1)/>
<cfset QuerySetCell(qxLookup, "xName","Delete",1)/>
<cfset QuerySetCell(qxLookup, "execution", "Select this to delete",1)/>
<cfoutput query="qxLookup">
<tr>
<td>
<a href="##" onclick="javascript:ColdFusion.navigate('xSelect/x.cfm?xNameVar=#url.xNameVar#&xID=#qxLookup.xID#&xName=#URLEncodedFormat(qxLookup.xName)#', '#xNameVar#');ColdFusion.Window.hide('#url.window#')">#qxLookup.xName#</a>
</td>
<td>#qxLookup.execution#</td>
</tr>
</cfoutput>
感谢您的任何帮助。
I am outputting a query but need to specify the first row of the result. I am adding the row with QueryAddRow() and setting the values with QuerySetCell().
I can create the row fine, I can add the content to that row fine. If I leave the argument for the row number off of QuerySetCell() then it all works great as the last result of the query when output. However, I need it to be first row of the query but when I try to set the row attribute with the QuerySetCell it just overwrites the first returned row from my query (i.e. my QueryAddRow() replaces the first record from my query). What I currently have is setting a variable from recordCount and arranging the output but there has to be a really simple way to do this that I am just not getting.
This code sets the row value to 1 but overwrites the first returned row from the query.
<cfquery name="qxLookup" datasource="#application.datasource#">
SELECT xID, xName, execution
FROM table
</cfquery>
<cfset QueryAddRow(qxLookup)/>
<cfset QuerySetCell(qxLookup, "xID","0",1)/>
<cfset QuerySetCell(qxLookup, "xName","Delete",1)/>
<cfset QuerySetCell(qxLookup, "execution", "Select this to delete",1)/>
<cfoutput query="qxLookup">
<tr>
<td>
<a href="##" onclick="javascript:ColdFusion.navigate('xSelect/x.cfm?xNameVar=#url.xNameVar#&xID=#qxLookup.xID#&xName=#URLEncodedFormat(qxLookup.xName)#', '#xNameVar#');ColdFusion.Window.hide('#url.window#')">#qxLookup.xName#</a>
</td>
<td>#qxLookup.execution#</td>
</tr>
</cfoutput>
Thanks for any help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我会向您的原始查询添加某种排序顺序列,并用固定值
1
填充它。将合成行中该列的值设置为值
0
。然后使用 query-of-queries 按
sortorder
列对记录集重新排序。I would add some kind of sort order column to your original query, populating it with a fixed value of
1
.Set the value of that column in your synthetic row to a value of
0
.Then use query-of-queries to reorder the recordset by the
sortorder
column.好吧,我以前处理过这个问题,对我来说,答案是有两个单独的查询。
第一个是您的正常查询,第二个是查询的查询,然后将它们进行并集,其中 qofq 高于正常查询,这应该按照您想要的顺序给出结果。
像这样的事情:
然后使用这个工具,您可以按照您喜欢的任何顺序放置查询,但请记住按标签使用顺序,以更改顺序...
Well I have dealt with this problem before, for me the answer was to have 2 seperate queries.
1st, being your normal query, 2nd being the query of queries, then do a union of them, with the qofq being above the normal query, and that should give you results in the order you want.
Something like this:
Then using this tool you can put queries in any order you like, but remember to use the order by tag, to change order...
只是上面的替代方案,但您可以将 ColdFusion 排除在外,并仅在 SQL 中使用类似(例如在 Oracle 中)
select 'myinsertedvalue' from Dual 的 方法来执行此操作
联盟
select myrealvalues from mutable
您可以与 Kens 排序列结合以获得完整排序。假设您从数据库获取主查询!
Just an alternative to above, but you could take ColdFusion out of the picture and do this solely in the SQL using something like (eg in oracle)
select 'myinsertedvalue' from dual
union
select myrealvalues from mutable
You could combine with Kens sort column to get full ordering. Assuming you are getting the main query from a DB!