大力:导出到Excel的存储过程,出现"查询提示超过了最大目录缓冲区 1023 字节(1246字节输入)" 如何解决?
stwx 2003-07-04 07:03:08 CREATE proc out2xls
@服务器名 varchar(255),
@库名 varchar(255),
@表名 varchar(255),
@用户名 varchar(100),
@密码 varchar(100),
@路径及文件名 varchar(255)
as
declare @temp1 nvarchar(4000),@temp2 varchar(8000)
set @temp1='select @value1='''',@value2='''' ;
select @value1=@value1+'',''''''+''[''+a.name+'']''+char(39),@value2=@value2+'',cast(''+''[''+a.name+'']''+ '' as varchar(200))'' from '+@库名+'..syscolumns a,'+@库名+'..sysobjects d where a.id=d.id and d.name='''+@表名+''''+' order by a.colorder'
print @temp1
exec sp_executesql @temp1,N'@value1 nvarchar(4000) output , @value2 varchar(8000) output',@temp1 output,@temp2 output
select @temp1=right(@temp1,len(@temp1)-1),@temp2=right(@temp2,len(@temp2)-1)
set @temp2='bcp "select '+@temp1+' union all SELECT '+@temp2+' FROM '+@库名+'..'+@表名+'" queryout '+@路径及文件名+' -c -S'+@服务器名+' -U'+@用户名+' -P'+@密码
print @temp2
EXEC master..xp_cmdshell @temp2
GO
---小的表(少字段)可以,大的表(多字段,40个左右)就不行, 好像是 bcp后面的字符超128就出现错误.大力:如何解决?