跪求解决1000条一导出的问题
小弟这有10万条记录 现在想每1000条导出一个txt文件 请教如何写这个sql语句?
[解决办法]
declare @i int
declare @sql nvarchar(1000)
set @i=0
select id=identity(int,1,1),* into [NewTable] from [Table] order by [Field]
while @i <=100000/1000
begin
set @sql= 'bcp "select * from db.dbo.[NewTable] where id between " '+ltrim(@i*1000+1)+ ' and '+ltrim((@i+1)*1000)+ ' queryout "d:\test '+ltrim(@i)+ '.txt " -c -Sserver -Uuser -Ppassword '
exec master..xp_cmdshell @sql
set @i=@i+1
end