逐记录导出text/ntext字段值为文本文件
来源:互联网 发布:淘宝店铺音乐怎么设置 编辑:程序博客网 时间:2024/04/18 04:04
/*--原帖地址:
http://community.csdn.net/Expert/topic/3851/3851741.xml?temp=.4726831
--*/
--测试数据
create table tb(id varchar(50) primary key,detail text)
insert tb select 'aaa','11111'
union all select 'bbb','43424'
union all select 'ccc','324234'
/*--处理要求
把上述表中的detail字段导出为文本文件,要求每条记录一个文件,文件名为id+.txt
即上述表中的数据要求导出为 aaa.txt,bbb.txt,ccc.txt
--*/
go
--处理的存储过程
create proc p_export
@path nvarchar(1000) --导出的文本文件保存的目录
as
declare @s nvarchar(4000)
if isnull(@path,'')='' set @path='c:/'
else if right(@path,1)<>'/' set @path=@path+'/'
--用游标构建每条记录的bcp导出语句,BCP的语法参考sql联机帮助
declare tb cursor local
for
select 'BCP "select detail from '
+quotename(db_name())
+'..tb where id='
+quotename(id,N'''')
+'" queryout "'+@path
+id+'.txt" /T /w'
from tb
open tb
fetch tb into @s
while @@fetch_status=0
begin
--调用xp_cmdshell存储过程执行bcp进行导出处理
exec master..xp_cmdshell @s,no_output
fetch tb into @s
end
close tb
deallocate tb
go
--调用
exec p_export 'c:/'
go
--删除测试
drop table tb
drop proc p_export
/*--原帖地址:
http://community.csdn.net/Expert/topic/3851/3851741.xml?temp=.4726831
--*/
--测试数据
create table tb(id varchar(50) primary key,detail text)
insert tb select 'aaa','11111'
union all select 'bbb','43424'
union all select 'ccc','324234'
/*--处理要求
把上述表中的detail字段导出为文本文件,要求每条记录一个文件,文件名为id+.txt
即上述表中的数据要求导出为 aaa.txt,bbb.txt,ccc.txt
--*/
go
--处理的存储过程
create proc p_export
@path nvarchar(1000) --导出的文本文件保存的目录
as
declare @s nvarchar(4000)
if isnull(@path,'')='' set @path='c:/'
else if right(@path,1)<>'/' set @path=@path+'/'
--用游标构建每条记录的bcp导出语句,BCP的语法参考sql联机帮助
declare tb cursor local
for
select 'BCP "select detail from '
+quotename(db_name())
+'..tb where id='
+quotename(id,N'''')
+'" queryout "'+@path
+id+'.txt" /T /w'
from tb
open tb
fetch tb into @s
while @@fetch_status=0
begin
--调用xp_cmdshell存储过程执行bcp进行导出处理
exec master..xp_cmdshell @s,no_output
fetch tb into @s
end
close tb
deallocate tb
go
--调用
exec p_export 'c:/'
go
--删除测试
drop table tb
drop proc p_export
/*--原帖地址:
http://community.csdn.net/Expert/topic/3851/3851741.xml?temp=.4726831
--*/
--测试数据
create table tb(id varchar(50) primary key,detail text)
insert tb select 'aaa','11111'
union all select 'bbb','43424'
union all select 'ccc','324234'
/*--处理要求
把上述表中的detail字段导出为文本文件,要求每条记录一个文件,文件名为id+.txt
即上述表中的数据要求导出为 aaa.txt,bbb.txt,ccc.txt
--*/
go
--处理的存储过程
create proc p_export
@path nvarchar(1000) --导出的文本文件保存的目录
as
declare @s nvarchar(4000)
if isnull(@path,'')='' set @path='c:/'
else if right(@path,1)<>'/' set @path=@path+'/'
--用游标构建每条记录的bcp导出语句,BCP的语法参考sql联机帮助
declare tb cursor local
for
select 'BCP "select detail from '
+quotename(db_name())
+'..tb where id='
+quotename(id,N'''')
+'" queryout "'+@path
+id+'.txt" /T /w'
from tb
open tb
fetch tb into @s
while @@fetch_status=0
begin
--调用xp_cmdshell存储过程执行bcp进行导出处理
exec master..xp_cmdshell @s,no_output
fetch tb into @s
end
close tb
deallocate tb
go
--调用
exec p_export 'c:/'
go
--删除测试
drop table tb
drop proc p_export
/*--原帖地址:
http://community.csdn.net/Expert/topic/3851/3851741.xml?temp=.4726831
--*/
--测试数据
create table tb(id varchar(50) primary key,detail text)
insert tb select 'aaa','11111'
union all select 'bbb','43424'
union all select 'ccc','324234'
/*--处理要求
把上述表中的detail字段导出为文本文件,要求每条记录一个文件,文件名为id+.txt
即上述表中的数据要求导出为 aaa.txt,bbb.txt,ccc.txt
--*/
go
--处理的存储过程
create proc p_export
@path nvarchar(1000) --导出的文本文件保存的目录
as
declare @s nvarchar(4000)
if isnull(@path,'')='' set @path='c:/'
else if right(@path,1)<>'/' set @path=@path+'/'
--用游标构建每条记录的bcp导出语句,BCP的语法参考sql联机帮助
declare tb cursor local
for
select 'BCP "select detail from '
+quotename(db_name())
+'..tb where id='
+quotename(id,N'''')
+'" queryout "'+@path
+id+'.txt" /T /w'
from tb
open tb
fetch tb into @s
while @@fetch_status=0
begin
--调用xp_cmdshell存储过程执行bcp进行导出处理
exec master..xp_cmdshell @s,no_output
fetch tb into @s
end
close tb
deallocate tb
go
--调用
exec p_export 'c:/'
go
--删除测试
drop table tb
drop proc p_export
/*--原帖地址:
http://community.csdn.net/Expert/topic/3851/3851741.xml?temp=.4726831
--*/
--测试数据
create table tb(id varchar(50) primary key,detail text)
insert tb select 'aaa','11111'
union all select 'bbb','43424'
union all select 'ccc','324234'
/*--处理要求
把上述表中的detail字段导出为文本文件,要求每条记录一个文件,文件名为id+.txt
即上述表中的数据要求导出为 aaa.txt,bbb.txt,ccc.txt
--*/
go
--处理的存储过程
create proc p_export
@path nvarchar(1000) --导出的文本文件保存的目录
as
declare @s nvarchar(4000)
if isnull(@path,'')='' set @path='c:/'
else if right(@path,1)<>'/' set @path=@path+'/'
--用游标构建每条记录的bcp导出语句,BCP的语法参考sql联机帮助
declare tb cursor local
for
select 'BCP "select detail from '
+quotename(db_name())
+'..tb where id='
+quotename(id,N'''')
+'" queryout "'+@path
+id+'.txt" /T /w'
from tb
open tb
fetch tb into @s
while @@fetch_status=0
begin
--调用xp_cmdshell存储过程执行bcp进行导出处理
exec master..xp_cmdshell @s,no_output
fetch tb into @s
end
close tb
deallocate tb
go
--调用
exec p_export 'c:/'
go
--删除测试
drop table tb
drop proc p_export
/*--原帖地址:
http://community.csdn.net/Expert/topic/3851/3851741.xml?temp=.4726831
--*/
--测试数据
create table tb(id varchar(50) primary key,detail text)
insert tb select 'aaa','11111'
union all select 'bbb','43424'
union all select 'ccc','324234'
/*--处理要求
把上述表中的detail字段导出为文本文件,要求每条记录一个文件,文件名为id+.txt
即上述表中的数据要求导出为 aaa.txt,bbb.txt,ccc.txt
--*/
go
--处理的存储过程
create proc p_export
@path nvarchar(1000) --导出的文本文件保存的目录
as
declare @s nvarchar(4000)
if isnull(@path,'')='' set @path='c:/'
else if right(@path,1)<>'/' set @path=@path+'/'
--用游标构建每条记录的bcp导出语句,BCP的语法参考sql联机帮助
declare tb cursor local
for
select 'BCP "select detail from '
+quotename(db_name())
+'..tb where id='
+quotename(id,N'''')
+'" queryout "'+@path
+id+'.txt" /T /w'
from tb
open tb
fetch tb into @s
while @@fetch_status=0
begin
--调用xp_cmdshell存储过程执行bcp进行导出处理
exec master..xp_cmdshell @s,no_output
fetch tb into @s
end
close tb
deallocate tb
go
--调用
exec p_export 'c:/'
go
--删除测试
drop table tb
drop proc p_export
/*--原帖地址:
http://community.csdn.net/Expert/topic/3851/3851741.xml?temp=.4726831
--*/
--测试数据
create table tb(id varchar(50) primary key,detail text)
insert tb select 'aaa','11111'
union all select 'bbb','43424'
union all select 'ccc','324234'
/*--处理要求
把上述表中的detail字段导出为文本文件,要求每条记录一个文件,文件名为id+.txt
即上述表中的数据要求导出为 aaa.txt,bbb.txt,ccc.txt
--*/
go
--处理的存储过程
create proc p_export
@path nvarchar(1000) --导出的文本文件保存的目录
as
declare @s nvarchar(4000)
if isnull(@path,'')='' set @path='c:/'
else if right(@path,1)<>'/' set @path=@path+'/'
--用游标构建每条记录的bcp导出语句,BCP的语法参考sql联机帮助
declare tb cursor local
for
select 'BCP "select detail from '
+quotename(db_name())
+'..tb where id='
+quotename(id,N'''')
+'" queryout "'+@path
+id+'.txt" /T /w'
from tb
open tb
fetch tb into @s
while @@fetch_status=0
begin
--调用xp_cmdshell存储过程执行bcp进行导出处理
exec master..xp_cmdshell @s,no_output
fetch tb into @s
end
close tb
deallocate tb
go
--调用
exec p_export 'c:/'
go
--删除测试
drop table tb
drop proc p_export
/*--原帖地址:
http://community.csdn.net/Expert/topic/3851/3851741.xml?temp=.4726831
--*/
--测试数据
create table tb(id varchar(50) primary key,detail text)
insert tb select 'aaa','11111'
union all select 'bbb','43424'
union all select 'ccc','324234'
/*--处理要求
把上述表中的detail字段导出为文本文件,要求每条记录一个文件,文件名为id+.txt
即上述表中的数据要求导出为 aaa.txt,bbb.txt,ccc.txt
--*/
go
--处理的存储过程
create proc p_export
@path nvarchar(1000) --导出的文本文件保存的目录
as
declare @s nvarchar(4000)
if isnull(@path,'')='' set @path='c:/'
else if right(@path,1)<>'/' set @path=@path+'/'
--用游标构建每条记录的bcp导出语句,BCP的语法参考sql联机帮助
declare tb cursor local
for
select 'BCP "select detail from '
+quotename(db_name())
+'..tb where id='
+quotename(id,N'''')
+'" queryout "'+@path
+id+'.txt" /T /w'
from tb
open tb
fetch tb into @s
while @@fetch_status=0
begin
--调用xp_cmdshell存储过程执行bcp进行导出处理
exec master..xp_cmdshell @s,no_output
fetch tb into @s
end
close tb
deallocate tb
go
--调用
exec p_export 'c:/'
go
--删除测试
drop table tb
drop proc p_export
/*--原帖地址:
http://community.csdn.net/Expert/topic/3851/3851741.xml?temp=.4726831
--*/
--测试数据
create table tb(id varchar(50) primary key,detail text)
insert tb select 'aaa','11111'
union all select 'bbb','43424'
union all select 'ccc','324234'
/*--处理要求
把上述表中的detail字段导出为文本文件,要求每条记录一个文件,文件名为id+.txt
即上述表中的数据要求导出为 aaa.txt,bbb.txt,ccc.txt
--*/
go
--处理的存储过程
create proc p_export
@path nvarchar(1000) --导出的文本文件保存的目录
as
declare @s nvarchar(4000)
if isnull(@path,'')='' set @path='c:/'
else if right(@path,1)<>'/' set @path=@path+'/'
--用游标构建每条记录的bcp导出语句,BCP的语法参考sql联机帮助
declare tb cursor local
for
select 'BCP "select detail from '
+quotename(db_name())
+'..tb where id='
+quotename(id,N'''')
+'" queryout "'+@path
+id+'.txt" /T /w'
from tb
open tb
fetch tb into @s
while @@fetch_status=0
begin
--调用xp_cmdshell存储过程执行bcp进行导出处理
exec master..xp_cmdshell @s,no_output
fetch tb into @s
end
close tb
deallocate tb
go
--调用
exec p_export 'c:/'
go
--删除测试
drop table tb
drop proc p_export
/*--原帖地址:
http://community.csdn.net/Expert/topic/3851/3851741.xml?temp=.4726831
--*/
--测试数据
create table tb(id varchar(50) primary key,detail text)
insert tb select 'aaa','11111'
union all select 'bbb','43424'
union all select 'ccc','324234'
/*--处理要求
把上述表中的detail字段导出为文本文件,要求每条记录一个文件,文件名为id+.txt
即上述表中的数据要求导出为 aaa.txt,bbb.txt,ccc.txt
--*/
go
--处理的存储过程
create proc p_export
@path nvarchar(1000) --导出的文本文件保存的目录
as
declare @s nvarchar(4000)
if isnull(@path,'')='' set @path='c:/'
else if right(@path,1)<>'/' set @path=@path+'/'
--用游标构建每条记录的bcp导出语句,BCP的语法参考sql联机帮助
declare tb cursor local
for
select 'BCP "select detail from '
+quotename(db_name())
+'..tb where id='
+quotename(id,N'''')
+'" queryout "'+@path
+id+'.txt" /T /w'
from tb
open tb
fetch tb into @s
while @@fetch_status=0
begin
--调用xp_cmdshell存储过程执行bcp进行导出处理
exec master..xp_cmdshell @s,no_output
fetch tb into @s
end
close tb
deallocate tb
go
--调用
exec p_export 'c:/'
go
--删除测试
drop table tb
drop proc p_export
/*--原帖地址:
http://community.csdn.net/Expert/topic/3851/3851741.xml?temp=.4726831
--*/
--测试数据
create table tb(id varchar(50) primary key,detail text)
insert tb select 'aaa','11111'
union all select 'bbb','43424'
union all select 'ccc','324234'
/*--处理要求
把上述表中的detail字段导出为文本文件,要求每条记录一个文件,文件名为id+.txt
即上述表中的数据要求导出为 aaa.txt,bbb.txt,ccc.txt
--*/
go
--处理的存储过程
create proc p_export
@path nvarchar(1000) --导出的文本文件保存的目录
as
declare @s nvarchar(4000)
if isnull(@path,'')='' set @path='c:/'
else if right(@path,1)<>'/' set @path=@path+'/'
--用游标构建每条记录的bcp导出语句,BCP的语法参考sql联机帮助
declare tb cursor local
for
select 'BCP "select detail from '
+quotename(db_name())
+'..tb where id='
+quotename(id,N'''')
+'" queryout "'+@path
+id+'.txt" /T /w'
from tb
open tb
fetch tb into @s
while @@fetch_status=0
begin
--调用xp_cmdshell存储过程执行bcp进行导出处理
exec master..xp_cmdshell @s,no_output
fetch tb into @s
end
close tb
deallocate tb
go
--调用
exec p_export 'c:/'
go
--删除测试
drop table tb
drop proc p_export
/*--原帖地址:
http://community.csdn.net/Expert/topic/3851/3851741.xml?temp=.4726831
--*/
--测试数据
create table tb(id varchar(50) primary key,detail text)
insert tb select 'aaa','11111'
union all select 'bbb','43424'
union all select 'ccc','324234'
/*--处理要求
把上述表中的detail字段导出为文本文件,要求每条记录一个文件,文件名为id+.txt
即上述表中的数据要求导出为 aaa.txt,bbb.txt,ccc.txt
--*/
go
--处理的存储过程
create proc p_export
@path nvarchar(1000) --导出的文本文件保存的目录
as
declare @s nvarchar(4000)
if isnull(@path,'')='' set @path='c:/'
else if right(@path,1)<>'/' set @path=@path+'/'
--用游标构建每条记录的bcp导出语句,BCP的语法参考sql联机帮助
declare tb cursor local
for
select 'BCP "select detail from '
+quotename(db_name())
+'..tb where id='
+quotename(id,N'''')
+'" queryout "'+@path
+id+'.txt" /T /w'
from tb
open tb
fetch tb into @s
while @@fetch_status=0
begin
--调用xp_cmdshell存储过程执行bcp进行导出处理
exec master..xp_cmdshell @s,no_output
fetch tb into @s
end
close tb
deallocate tb
go
--调用
exec p_export 'c:/'
go
--删除测试
drop table tb
drop proc p_export
/*--原帖地址:
http://community.csdn.net/Expert/topic/3851/3851741.xml?temp=.4726831
--*/
--测试数据
create table tb(id varchar(50) primary key,detail text)
insert tb select 'aaa','11111'
union all select 'bbb','43424'
union all select 'ccc','324234'
/*--处理要求
把上述表中的detail字段导出为文本文件,要求每条记录一个文件,文件名为id+.txt
即上述表中的数据要求导出为 aaa.txt,bbb.txt,ccc.txt
--*/
go
--处理的存储过程
create proc p_export
@path nvarchar(1000) --导出的文本文件保存的目录
as
declare @s nvarchar(4000)
if isnull(@path,'')='' set @path='c:/'
else if right(@path,1)<>'/' set @path=@path+'/'
--用游标构建每条记录的bcp导出语句,BCP的语法参考sql联机帮助
declare tb cursor local
for
select 'BCP "select detail from '
+quotename(db_name())
+'..tb where id='
+quotename(id,N'''')
+'" queryout "'+@path
+id+'.txt" /T /w'
from tb
open tb
fetch tb into @s
while @@fetch_status=0
begin
--调用xp_cmdshell存储过程执行bcp进行导出处理
exec master..xp_cmdshell @s,no_output
fetch tb into @s
end
close tb
deallocate tb
go
--调用
exec p_export 'c:/'
go
--删除测试
drop table tb
drop proc p_export
/*--原帖地址:
http://community.csdn.net/Expert/topic/3851/3851741.xml?temp=.4726831
--*/
--测试数据
create table tb(id varchar(50) primary key,detail text)
insert tb select 'aaa','11111'
union all select 'bbb','43424'
union all select 'ccc','324234'
/*--处理要求
把上述表中的detail字段导出为文本文件,要求每条记录一个文件,文件名为id+.txt
即上述表中的数据要求导出为 aaa.txt,bbb.txt,ccc.txt
--*/
go
--处理的存储过程
create proc p_export
@path nvarchar(1000) --导出的文本文件保存的目录
as
declare @s nvarchar(4000)
if isnull(@path,'')='' set @path='c:/'
else if right(@path,1)<>'/' set @path=@path+'/'
--用游标构建每条记录的bcp导出语句,BCP的语法参考sql联机帮助
declare tb cursor local
for
select 'BCP "select detail from '
+quotename(db_name())
+'..tb where id='
+quotename(id,N'''')
+'" queryout "'+@path
+id+'.txt" /T /w'
from tb
open tb
fetch tb into @s
while @@fetch_status=0
begin
--调用xp_cmdshell存储过程执行bcp进行导出处理
exec master..xp_cmdshell @s,no_output
fetch tb into @s
end
close tb
deallocate tb
go
--调用
exec p_export 'c:/'
go
--删除测试
drop table tb
drop proc p_export
/*--原帖地址:
http://community.csdn.net/Expert/topic/3851/3851741.xml?temp=.4726831
--*/
--测试数据
create table tb(id varchar(50) primary key,detail text)
insert tb select 'aaa','11111'
union all select 'bbb','43424'
union all select 'ccc','324234'
/*--处理要求
把上述表中的detail字段导出为文本文件,要求每条记录一个文件,文件名为id+.txt
即上述表中的数据要求导出为 aaa.txt,bbb.txt,ccc.txt
--*/
go
--处理的存储过程
create proc p_export
@path nvarchar(1000) --导出的文本文件保存的目录
as
declare @s nvarchar(4000)
if isnull(@path,'')='' set @path='c:/'
else if right(@path,1)<>'/' set @path=@path+'/'
--用游标构建每条记录的bcp导出语句,BCP的语法参考sql联机帮助
declare tb cursor local
for
select 'BCP "select detail from '
+quotename(db_name())
+'..tb where id='
+quotename(id,N'''')
+'" queryout "'+@path
+id+'.txt" /T /w'
from tb
open tb
fetch tb into @s
while @@fetch_status=0
begin
--调用xp_cmdshell存储过程执行bcp进行导出处理
exec master..xp_cmdshell @s,no_output
fetch tb into @s
end
close tb
deallocate tb
go
--调用
exec p_export 'c:/'
go
--删除测试
drop table tb
drop proc p_export
/*--原帖地址:
http://community.csdn.net/Expert/topic/3851/3851741.xml?temp=.4726831
--*/
--测试数据
create table tb(id varchar(50) primary key,detail text)
insert tb select 'aaa','11111'
union all select 'bbb','43424'
union all select 'ccc','324234'
/*--处理要求
把上述表中的detail字段导出为文本文件,要求每条记录一个文件,文件名为id+.txt
即上述表中的数据要求导出为 aaa.txt,bbb.txt,ccc.txt
--*/
go
--处理的存储过程
create proc p_export
@path nvarchar(1000) --导出的文本文件保存的目录
as
declare @s nvarchar(4000)
if isnull(@path,'')='' set @path='c:/'
else if right(@path,1)<>'/' set @path=@path+'/'
--用游标构建每条记录的bcp导出语句,BCP的语法参考sql联机帮助
declare tb cursor local
for
select 'BCP "select detail from '
+quotename(db_name())
+'..tb where id='
+quotename(id,N'''')
+'" queryout "'+@path
+id+'.txt" /T /w'
from tb
open tb
fetch tb into @s
while @@fetch_status=0
begin
--调用xp_cmdshell存储过程执行bcp进行导出处理
exec master..xp_cmdshell @s,no_output
fetch tb into @s
end
close tb
deallocate tb
go
--调用
exec p_export 'c:/'
go
--删除测试
drop table tb
drop proc p_export
/*--原帖地址:
http://community.csdn.net/Expert/topic/3851/3851741.xml?temp=.4726831
--*/
--测试数据
create table tb(id varchar(50) primary key,detail text)
insert tb select 'aaa','11111'
union all select 'bbb','43424'
union all select 'ccc','324234'
/*--处理要求
把上述表中的detail字段导出为文本文件,要求每条记录一个文件,文件名为id+.txt
即上述表中的数据要求导出为 aaa.txt,bbb.txt,ccc.txt
--*/
go
--处理的存储过程
create proc p_export
@path nvarchar(1000) --导出的文本文件保存的目录
as
declare @s nvarchar(4000)
if isnull(@path,'')='' set @path='c:/'
else if right(@path,1)<>'/' set @path=@path+'/'
--用游标构建每条记录的bcp导出语句,BCP的语法参考sql联机帮助
declare tb cursor local
for
select 'BCP "select detail from '
+quotename(db_name())
+'..tb where id='
+quotename(id,N'''')
+'" queryout "'+@path
+id+'.txt" /T /w'
from tb
open tb
fetch tb into @s
while @@fetch_status=0
begin
--调用xp_cmdshell存储过程执行bcp进行导出处理
exec master..xp_cmdshell @s,no_output
fetch tb into @s
end
close tb
deallocate tb
go
--调用
exec p_export 'c:/'
go
--删除测试
drop table tb
drop proc p_export
/*--原帖地址:
http://community.csdn.net/Expert/topic/3851/3851741.xml?temp=.4726831
--*/
--测试数据
create table tb(id varchar(50) primary key,detail text)
insert tb select 'aaa','11111'
union all select 'bbb','43424'
union all select 'ccc','324234'
/*--处理要求
把上述表中的detail字段导出为文本文件,要求每条记录一个文件,文件名为id+.txt
即上述表中的数据要求导出为 aaa.txt,bbb.txt,ccc.txt
--*/
go
--处理的存储过程
create proc p_export
@path nvarchar(1000) --导出的文本文件保存的目录
as
declare @s nvarchar(4000)
if isnull(@path,'')='' set @path='c:/'
else if right(@path,1)<>'/' set @path=@path+'/'
--用游标构建每条记录的bcp导出语句,BCP的语法参考sql联机帮助
declare tb cursor local
for
select 'BCP "select detail from '
+quotename(db_name())
+'..tb where id='
+quotename(id,N'''')
+'" queryout "'+@path
+id+'.txt" /T /w'
from tb
open tb
fetch tb into @s
while @@fetch_status=0
begin
--调用xp_cmdshell存储过程执行bcp进行导出处理
exec master..xp_cmdshell @s,no_output
fetch tb into @s
end
close tb
deallocate tb
go
--调用
exec p_export 'c:/'
go
--删除测试
drop table tb
drop proc p_export
/*--原帖地址:
http://community.csdn.net/Expert/topic/3851/3851741.xml?temp=.4726831
--*/
--测试数据
create table tb(id varchar(50) primary key,detail text)
insert tb select 'aaa','11111'
union all select 'bbb','43424'
union all select 'ccc','324234'
/*--处理要求
把上述表中的detail字段导出为文本文件,要求每条记录一个文件,文件名为id+.txt
即上述表中的数据要求导出为 aaa.txt,bbb.txt,ccc.txt
--*/
go
--处理的存储过程
create proc p_export
@path nvarchar(1000) --导出的文本文件保存的目录
as
declare @s nvarchar(4000)
if isnull(@path,'')='' set @path='c:/'
else if right(@path,1)<>'/' set @path=@path+'/'
--用游标构建每条记录的bcp导出语句,BCP的语法参考sql联机帮助
declare tb cursor local
for
select 'BCP "select detail from '
+quotename(db_name())
+'..tb where id='
+quotename(id,N'''')
+'" queryout "'+@path
+id+'.txt" /T /w'
from tb
open tb
fetch tb into @s
while @@fetch_status=0
begin
--调用xp_cmdshell存储过程执行bcp进行导出处理
exec master..xp_cmdshell @s,no_output
fetch tb into @s
end
close tb
deallocate tb
go
--调用
exec p_export 'c:/'
go
--删除测试
drop table tb
drop proc p_export
/*--原帖地址:
http://community.csdn.net/Expert/topic/3851/3851741.xml?temp=.4726831
--*/
--测试数据
create table tb(id varchar(50) primary key,detail text)
insert tb select 'aaa','11111'
union all select 'bbb','43424'
union all select 'ccc','324234'
/*--处理要求
把上述表中的detail字段导出为文本文件,要求每条记录一个文件,文件名为id+.txt
即上述表中的数据要求导出为 aaa.txt,bbb.txt,ccc.txt
--*/
go
--处理的存储过程
create proc p_export
@path nvarchar(1000) --导出的文本文件保存的目录
as
declare @s nvarchar(4000)
if isnull(@path,'')='' set @path='c:/'
else if right(@path,1)<>'/' set @path=@path+'/'
--用游标构建每条记录的bcp导出语句,BCP的语法参考sql联机帮助
declare tb cursor local
for
select 'BCP "select detail from '
+quotename(db_name())
+'..tb where id='
+quotename(id,N'''')
+'" queryout "'+@path
+id+'.txt" /T /w'
from tb
open tb
fetch tb into @s
while @@fetch_status=0
begin
--调用xp_cmdshell存储过程执行bcp进行导出处理
exec master..xp_cmdshell @s,no_output
fetch tb into @s
end
close tb
deallocate tb
go
--调用
exec p_export 'c:/'
go
--删除测试
drop table tb
drop proc p_export
/*--原帖地址:
http://community.csdn.net/Expert/topic/3851/3851741.xml?temp=.4726831
--*/
--测试数据
create table tb(id varchar(50) primary key,detail text)
insert tb select 'aaa','11111'
union all select 'bbb','43424'
union all select 'ccc','324234'
/*--处理要求
把上述表中的detail字段导出为文本文件,要求每条记录一个文件,文件名为id+.txt
即上述表中的数据要求导出为 aaa.txt,bbb.txt,ccc.txt
--*/
go
--处理的存储过程
create proc p_export
@path nvarchar(1000) --导出的文本文件保存的目录
as
declare @s nvarchar(4000)
if isnull(@path,'')='' set @path='c:/'
else if right(@path,1)<>'/' set @path=@path+'/'
--用游标构建每条记录的bcp导出语句,BCP的语法参考sql联机帮助
declare tb cursor local
for
select 'BCP "select detail from '
+quotename(db_name())
+'..tb where id='
+quotename(id,N'''')
+'" queryout "'+@path
+id+'.txt" /T /w'
from tb
open tb
fetch tb into @s
while @@fetch_status=0
begin
--调用xp_cmdshell存储过程执行bcp进行导出处理
exec master..xp_cmdshell @s,no_output
fetch tb into @s
end
close tb
deallocate tb
go
--调用
exec p_export 'c:/'
go
--删除测试
drop table tb
drop proc p_export
/*--原帖地址:
http://community.csdn.net/Expert/topic/3851/3851741.xml?temp=.4726831
--*/
--测试数据
create table tb(id varchar(50) primary key,detail text)
insert tb select 'aaa','11111'
union all select 'bbb','43424'
union all select 'ccc','324234'
/*--处理要求
把上述表中的detail字段导出为文本文件,要求每条记录一个文件,文件名为id+.txt
即上述表中的数据要求导出为 aaa.txt,bbb.txt,ccc.txt
--*/
go
--处理的存储过程
create proc p_export
@path nvarchar(1000) --导出的文本文件保存的目录
as
declare @s nvarchar(4000)
if isnull(@path,'')='' set @path='c:/'
else if right(@path,1)<>'/' set @path=@path+'/'
--用游标构建每条记录的bcp导出语句,BCP的语法参考sql联机帮助
declare tb cursor local
for
select 'BCP "select detail from '
+quotename(db_name())
+'..tb where id='
+quotename(id,N'''')
+'" queryout "'+@path
+id+'.txt" /T /w'
from tb
open tb
fetch tb into @s
while @@fetch_status=0
begin
--调用xp_cmdshell存储过程执行bcp进行导出处理
exec master..xp_cmdshell @s,no_output
fetch tb into @s
end
close tb
deallocate tb
go
--调用
exec p_export 'c:/'
go
--删除测试
drop table tb
drop proc p_export
/*--原帖地址:
http://community.csdn.net/Expert/topic/3851/3851741.xml?temp=.4726831
--*/
--测试数据
create table tb(id varchar(50) primary key,detail text)
insert tb select 'aaa','11111'
union all select 'bbb','43424'
union all select 'ccc','324234'
/*--处理要求
把上述表中的detail字段导出为文本文件,要求每条记录一个文件,文件名为id+.txt
即上述表中的数据要求导出为 aaa.txt,bbb.txt,ccc.txt
--*/
go
--处理的存储过程
create proc p_export
@path nvarchar(1000) --导出的文本文件保存的目录
as
declare @s nvarchar(4000)
if isnull(@path,'')='' set @path='c:/'
else if right(@path,1)<>'/' set @path=@path+'/'
--用游标构建每条记录的bcp导出语句,BCP的语法参考sql联机帮助
declare tb cursor local
for
select 'BCP "select detail from '
+quotename(db_name())
+'..tb where id='
+quotename(id,N'''')
+'" queryout "'+@path
+id+'.txt" /T /w'
from tb
open tb
fetch tb into @s
while @@fetch_status=0
begin
--调用xp_cmdshell存储过程执行bcp进行导出处理
exec master..xp_cmdshell @s,no_output
fetch tb into @s
end
close tb
deallocate tb
go
--调用
exec p_export 'c:/'
go
--删除测试
drop table tb
drop proc p_export
/*--原帖地址:
http://community.csdn.net/Expert/topic/3851/3851741.xml?temp=.4726831
--*/
--测试数据
create table tb(id varchar(50) primary key,detail text)
insert tb select 'aaa','11111'
union all select 'bbb','43424'
union all select 'ccc','324234'
/*--处理要求
把上述表中的detail字段导出为文本文件,要求每条记录一个文件,文件名为id+.txt
即上述表中的数据要求导出为 aaa.txt,bbb.txt,ccc.txt
--*/
go
--处理的存储过程
create proc p_export
@path nvarchar(1000) --导出的文本文件保存的目录
as
declare @s nvarchar(4000)
if isnull(@path,'')='' set @path='c:/'
else if right(@path,1)<>'/' set @path=@path+'/'
--用游标构建每条记录的bcp导出语句,BCP的语法参考sql联机帮助
declare tb cursor local
for
select 'BCP "select detail from '
+quotename(db_name())
+'..tb where id='
+quotename(id,N'''')
+'" queryout "'+@path
+id+'.txt" /T /w'
from tb
open tb
fetch tb into @s
while @@fetch_status=0
begin
--调用xp_cmdshell存储过程执行bcp进行导出处理
exec master..xp_cmdshell @s,no_output
fetch tb into @s
end
close tb
deallocate tb
go
--调用
exec p_export 'c:/'
go
--删除测试
drop table tb
drop proc p_export
- 逐记录导出text/ntext字段值为文本文件
- 逐记录导出text/ntext字段值为文本文件
- 逐记录导出text/ntext字段值为文本文件
- 逐记录导出text/ntext字段值为文本文件
- 逐记录导出text/ntext字段值为文本文件
- 逐记录导出text/ntext字段值为文本文件
- 逐记录导出text/ntext字段值为文本文件
- 逐记录导出text/ntext字段值为文本文件
- 逐记录导出text/ntext字段值为文本文件
- 逐记录导出text/ntext字段值为文本文件
- 逐记录导出text/ntext字段值为文本文件
- 逐记录导出text/ntext字段值为文本文件
- 逐记录导出text/ntext字段值为文本文件
- 逐记录导出text/ntext字段值为文本文件
- 逐记录导出text ntext字段值为文本文件
- MsSql 数据表中把字段类型为text的字段内容导出为文本文件
- 导出ntext数据到文本文件,一条记录一个文件
- 查找字段类型为ntext或者text的列
- 也谈内容引擎,内容如何为王?
- 跨域或者Internet访问Remoting[Remoting FAQ]
- 做新闻记者的准则-著名战地记者阿内特的访谈
- 也说假如keso搞了个“对牛乱博网”
- oracle 11g下载 Oracle 10g下载 Oracle 9i下载
- 逐记录导出text/ntext字段值为文本文件
- 郑昀邀请开发(Java爬虫/C++自然语言)人才加盟[工作地点:北京]
- 团队初创两月小结
- 薄积薄发的国内BlogNetwork
- 话题讨论:中国SaaS概念能否一飞冲天?
- 民生与草根是互联网的未来-英雄大会最终总结篇
- 关于SIP中的Authorization
- {基于Applet的J2ME模拟器}和{microemulator}[J2ME推荐]
- [MSN谈话]专注、口碑和猎头