create procedure bcp2
@tablename varchar(40),
@where_statement varchar(255)
as begin
declare @sqltext varchar(6000)
declare @cname varchar(40)
declare @typ int
--select @tablename = 'tstore'
---構造insert 語句
--adaptive server has expanded all '*' elements in the following statement
select sc.id, sc.number, sc.colid, sc.status, sc.type, sc.length, sc.offset, sc.usertype, sc.cdefault, sc.domain, sc.name, sc.printfmt, sc.prec, sc.scale, sc.remote_type, sc.remote_name, sc.xstatus, sc.xtype, sc.xdbid, sc.accessrule, sc.status2 into #t
from syscolumns sc, sysobjects so
where sc.id = so.id
and so.name = @tablename
select @sqltext = 'insert into ' + @tablename + '('
while exists(select 1 from #t)
begin
set rowcount 1
select @cname = name from #t
select @sqltext = @sqltext + @cname + ','
delete #t
set rowcount 0
end
select @sqltext = substring(@sqltext, 1, char_length(@sqltext) - 1) + ')'
drop table #t
---構造insert 語句 end
---構造values 語句
--adaptive server has expanded all '*' elements in the following statement
select sc.id, sc.number, sc.colid, sc.status, sc.type, sc.length, sc.offset, sc.usertype, sc.cdefault, sc.domain, sc.name, sc.printfmt, sc.prec, sc.scale, sc.remote_type, sc.remote_name, sc.xstatus, sc.xtype, sc.xdbid, sc.accessrule, sc.status2 into #t1
from syscolumns sc, sysobjects so
where sc.id = so.id
and so.name = @tablename
--select * from #t1
select @sqltext = @sqltext + 'values('
while exists(select 1 from #t1)
begin
set rowcount 1
select @cname = name, @typ = type from #t1
if charindex('n', @cname) = 1
select @sqltext = @sqltext + ''' + convert(varchar, ' + @cname + ') + '','
else if @typ =38
select @sqltext = @sqltext + ''' + convert(varchar, ' + @cname + ') + '','
else if @typ =50
select @sqltext = @sqltext + ''' + convert(varchar, ' + @cname + ') + '','
else if @typ =56
select @sqltext = @sqltext + ''' + convert(varchar, ' + @cname + ') + '','
else if @typ =52
select @sqltext = @sqltext + ''' + convert(varchar, ' + @cname + ') + '','
else if @typ =35
select @sqltext = @sqltext + ''''''' + convert(varchar, ' + @cname + ') + '''''','
else if charindex('d', @cname) = 1
select @sqltext = @sqltext + ''''''' + convert(varchar, ' + @cname + ') + '''''','
else select @sqltext = @sqltext + ''''''' + ' + @cname + ' + '''''','
delete #t1
set rowcount 0
end
select @sqltext = substring(@sqltext, 1, char_length(@sqltext) - 1)
select @sqltext = 'select ''' + @sqltext + ')'' from ' + @tablename + ' ' + @where_statement
--select @sqltext = 'insert into t3 select sqltext=''' + @sqltext + ')'' from ' + @tablename
print @sqltext
--select char_length(@sqltext)
--exec( 'create table t3(sc1 text)')
exec( @sqltext)
--exec( 'select * from t3 go drop table t3')
drop table #t1
---構造values 語句 end
--select convert(varchar(5000), 'insert into tstore(sstoreno, sstoredesc) values (''' + sstoreno+ ''', ''' + sstoredesc + ''')') from tstore
--drop table t1
--create table t1(sc1 varchar(20), nc2 int, dc3 datetime)
end
mysql資料匯入匯出文字檔案
匯出 1 select from 表名 into outfile 檔案儲存路徑 sql.txt 注意 檔案屬組和屬主需要改為mysql my.cnf中需要配置新增檔案安全許可權secure file priv data 只是匯出資料,不會匯出表結構,需要mysqldump匯出表結構 2 mysql ...
MSSQL匯入匯出資料
匯出到excel exec master.xp cmdshell bcp settledb.dbo.shanghu out c temp1.xls c q s gnetdata gnetdata u sa p 匯入excel select from opendatasource microsoft....
MongoDB資料庫匯出檔案到txt文字
一,mongodb匯出資料 1.3.2版本啟動mongodb資料庫命令 cd c program files mongodb server 3.2 bin mongod config d mongodb etc mongodb.conf 2.進入到目錄 bin下cd c program files ...