简体   繁体   English

SQL查询的值不超过2100

[英]SQL query not taking values more than 2100

SELECT MachineID, MachineName, count(ID) as Total, sum(Size) as TotalSize 
  FROM Files 
  join Machines on Files.MachineID = Machines.MachineID 
 Where Files.MachineID In(sql.Append(string.Format("@MachineId{0}", i));
 group by Files.MachineID,MachineName

now when the machinId count is less than 2100 the query is performed and if it machines go above 2100 an error is thrown Error: 现在当machinId计数小于2100时,执行查询,如果机器超过2100,则抛出错误错误:

The incoming tabular data stream (TDS) remote procedure call (RPC) protocol stream is incorrect. 传入的表格数据流(TDS)远程过程调用(RPC)协议流不正确。 Too many parameters were provided in this RPC request. 此RPC请求中提供的参数太多。 The maximum is 2100. 最高为2100。

how do i make increase the limit or just avoid getting this error.. and put values in gridview thanks.. 我如何增加限制或只是避免得到这个错误..并将值放在gridview感谢..

You don't say in your example where your "sql" variable comes from but if you manually build your 'IN' list (by building a string with comma delimited values in your IN statement), then all popular relational DBs have a limit to how many values you can specify in a static IN clause. 你没有在你的例子中说你的“sql”变量来自哪个,但如果你手动建立你的'IN'列表(通过在IN语句中构建一个带逗号分隔值的字符串),那么所有流行的关系数据库都有一个限制您可以在静态IN子句中指定多少个值。 The database your are using has a 2100 limit. 您正在使用的数据库具有2100限制。 I believe Oracle is 1000 我相信Oracle是1000

you could use string functions. 你可以使用字符串函数。 In SQL Server your WHERE clause would be something like 在SQL Server中,您的WHERE子句就像

...WHERE CHARINDEX(':' + <: delimited list of machine IDs> + ':', 
       ':' + CAST(Files.MachineID as VARCHAR(10)) + ':') <> 0

The : delimiters are necessary to prevent 100 from matching with 1001, 1002, 2100, etc. A sample query string would be :分隔符是必要的,以防止100与1001,1002,2100等匹配。示例查询字符串将是

...WHERE CHARINDEX(':1000:1001:1002:1005:', 
       ':' + CAST(Files.MachineID as VARCHAR(10)) + ':') <> 0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM