首先将值加载到 XML
<cfset var strResult = '<ul class="xoxo">'>
<cfloop query="qryOrd">
<cfset strResult &= '<li>#xmlformat(ord_no)#</li>'>
</cfloop>
<cfset strResult &= '</ul>'>
然后在sql查询中使用xml
<cfquery name="result.qryData">
DECLARE @xmlOrd_no xml = <cfqueryparam cfsqltype="CF_SQL_varchar" value="#strResult#">
DECLARE @tblOrd_no TABLE (ID varchar(20))
INSERT INTO @tblOrd_no
SELECT tbl.Col.value('.', 'varchar(20)')
FROM @xmlOrd_no.nodes('/ul/li') tbl(Col)
SELECT sub_acct_no, ...
FROM dbo.Closed_ORDER
WHERE ord_no IN (SELECT ID FROM @tblOrd_no)
</cfquery>
您还可以转储 XML,它在 HTML 中正确格式化
<cfoutput>#strResult#</cfoutput>