你可以把这些成千上万个写到一个表里再 select * from table where ID in (select id from 表)好处:可以解决你的问题,可以不用没次执行都要传递千上万个id到sqlserver里,只要调用一下这个表就OK了。
用表变量就行了嘛. 至于效率,你肯定要从一个地方得到要查询的ID.这个根据你的情况看是否有更有效的方法. 你最好说明你的实际情况.dclare @tb table(id int) insert into @tb select 1 union all select 2 ...你要查询的ID值select * from table where ID in (select id from @tb)
将CArray<int,int>转换为String作为参数传递给存储过程,由存储过程执行sql并返回结果集。 create proc filterFromIdSet @idSet text as exec('select * from table where ID in ( ('+@idSet+')') go
select * from table where ID in (select id from 表)好处:可以解决你的问题,可以不用没次执行都要传递千上万个id到sqlserver里,只要调用一下这个表就OK了。
至于效率,你肯定要从一个地方得到要查询的ID.这个根据你的情况看是否有更有效的方法.
你最好说明你的实际情况.dclare @tb table(id int)
insert into @tb
select 1
union all select 2
...你要查询的ID值select * from table where ID in (select id from @tb)
select * from 一个有多个字段的表 where id in(select id from 现在已知一个ID的集合)
create proc filterFromIdSet
@idSet text
as
exec('select * from table where ID in ( ('+@idSet+')')
go