'bcp' 不是内部或外部命令,也不是可运行的程序?
看看在c:/program files/microsoft sql server/80/tools/binn里面有没有bcp.exe这个文件
然后看看path里面加c:/program files/microsoft sql server/80/tools/binn这个目录没有.
右键我的电脑--属性--高级--环境变量--在系统变量中找到path--编辑
在变量值的最后加上:
c:/program files/microsoft sql server/80/tools/binn
*/
/**********************************************************************
存储过程: p_savexml
功能: 生成xml文件
参数: 表名
返回: 指定目录的xml文件
调用方法: 传递中间表tb_tablecolumn_t存在的表名
exec p_zehuasavexml 'wq_stinfo_b,wq_phy_d','d:/xx.xml'
最后更改日期: 2005-8-17
联系方式: [email protected]
备注: 根据中间表生成符合标准格式的xml文件
www.knowsky.com
**********************************************************************/
/*
exec p_zehuasavexml 'wq_stinfo_b,wq_phy_d','d:/xx.xml'
*/
go
create proc p_zehuasavexml
@tablecodes varchar(8000),
@fname varchar(1000)='c:/tmp.xml' --默认保存的xml文件地址
as
declare @sql nvarchar(200),@sql1 varchar(400)
declare @cnt int,@table_name varchar(20)
declare @i int,@tablecode varchar(20)
declare @err int,@src varchar(255),@desc varchar(255)
create table ##t(re nvarchar(4000))
insert ##t
select re='<?xml version="1.0" encoding="gb2312"?>'
union all select '<zehuatableinfoxml>'
set @i=charindex(',',@tablecodes)
while @i>0
begin
set @tablecode=left(@tablecodes,@i-1)
set @sql=''
set @sql=n'select @cnt=count(*),@table_name=max(table_name) from '
set @[email protected]+n'('
set @[email protected]+n'select top 100 percent * from tb_tablecolumn_t where '
set @[email protected]+n'table_code='''[email protected]+''' and columns_iskey=''√'' '
set @[email protected]+n'order by columns_sort '
set @[email protected]+n')'
set @[email protected]+n'a'
exec sp_executesql @sql,n'@cnt int output,@table_name varchar(20) output',@cnt output,@table_name output --计算主键的个数,表名
insert ##t
select '<'[email protected]+' table_name="'[email protected]_name+'" pk="'+cast(@cnt as varchar)+'">'
union all
select space(4)+'<columns columns_name="'+cast(columns_name as varchar)+'"
'+space(8)+'table_code="'+isnull(@tablecode,'')+'"
'+space(8)+'columns_visible="'+isnull(columns_visible,'')+'"/>'
from tb_tablecolumn_t where table_code=''[email protected]+''
union all select '</'[email protected]+'>'
set @tablecodes=right(@tablecodes,len(@tablecodes)[email protected])
set @i=charindex(',',@tablecodes)
end
if len(@tablecodes)>0
begin
set @sql=''
set @sql=n'select @cnt=count(*),@table_name=max(table_name) from '
set @[email protected]+n'('
set @[email protected]+n'select top 100 percent * from tb_tablecolumn_t where '
set @[email protected]+n'table_code='''[email protected]+''' and columns_iskey=''√'' '
set @[email protected]+n'order by columns_sort '
set @[email protected]+n')'
set @[email protected]+n'a'
exec sp_executesql @sql,n'@cnt int output,@table_name varchar(20) output',@cnt output,@table_name output --计算主键的个数,表名
insert ##t
select '<'[email protected]+' table_name="'[email protected]_name+'" pk="'+cast(@cnt as varchar)+'">'
union all
select space(4)+'<columns columns_name="'+cast(columns_name as varchar)+'"
'+space(8)+'table_code="'+isnull(@tablecodes,'')+'"
'+space(8)+'columns_visible="'+isnull(columns_visible,'')+'"/>'
from tb_tablecolumn_t where table_code=''[email protected]+''
union all select '</'[email protected]+'>'
union all select '</zehuatableinfoxml>'
end
exec('master..xp_cmdshell ''bcp ##t out "'[email protected]+'" /p"" /c''')
drop table ##t
go
/*
测试环境:
windows 2000 server + sql 2000测试通过
*/
新闻热点
疑难解答