提高跨服务器获取数据速度


select top(500) ItemID into #t from [ERPServer].db1.dbo.tblOrder ;

create index ix_1 on #t(ItemID);

declare @zitem_list nvarchar(max) = N'(''xx';
select @zitem_list=@zitem_list+''',N''' + itemid from #t;
set @zitem_list = @zitem_list + ''')';

declare @zsql nvarchar(max);
set @zsql = N'select * from [ERPServer].db1.dbo.tblOrder
where ItemID in ' + @zitem_list;

select @zsql;
exec [ERPServer].db1.dbo.sp_executesql @zsql

drop table #t;

posted @ 2021-06-25 11:55  Ender.Lu  阅读(72)  评论(0)    收藏  举报