Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
558 views
in Technique[技术] by (71.8m points)

tsql - Select IN on more than 2100 values

How can you do a select in on more than 2100 values?

<cfquery name="result.qryData">
  SELECT    sub_acct_no,  ...
  FROM  dbo.Closed_ORDER
  WHERE ord_no IN <cfqueryparam cfsqltype="CF_SQL_varchar" value="#ValueList(qryOrd.ord_no)#" list="yes">
</cfquery>

Because of the ways that the tables are setup, linked Servers and JOINS are not an option.

When this is ran an error this thrown because there are new many fields being passed in.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

First load the values into XML

<cfset var strResult = '<ul class="xoxo">'>
<cfloop query="qryOrd">
    <cfset strResult &= '<li>#xmlformat(ord_no)#</li>'>
</cfloop>
<cfset strResult &= '</ul>'>

Then use the xml in the sql query

<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>

You can also do a dump of the XML and it is properly formatted in HTML

 <cfoutput>#strResult#</cfoutput>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...