從資料庫中匯出資料

2021-05-25 22:10:38 字數 452 閱讀 5209

首先開啟xp_cmdshell許可權:

exec sp_configure 'show advanced options', 1;reconfigure;exec sp_configure 'xp_cmdshell', 1;reconfigure;

1,匯出資料到txt

exec master..xp_cmdshell 'bcp "資料庫名..表名" out "檔名t" -c -t -u sa -p 密碼'

2,匯出資料到excel

exec master..xp_cmdshell 'bcp 資料庫名..表名 out 檔名 -c  -t -u sa -p 密碼'

若是資料庫表之間複製資料就沒這麼麻煩了,用如下sql語句

insert into 目標表名(欄位1,欄位2) select 源表名.欄位1,源表名.欄位2 from 源表名

同時要注意欄位的類別一定要匹配。

從資料庫中匯出資料庫文件

select case when a.colorder 1 then d.name else end n 表名 a.colorder n 字段序號 a.name n 欄位名 case when columnproperty a.id,a.name,isidentity 1 then else end...

從資料庫中匯出 csv檔案

需求 本次將資料庫中的資料匯出成.csv檔案 office可以開啟 資料的生成,根據你所選中的資料進行生成 params activity id 活動的id params form id 匯出資料中選中的活動id public function exportdata activity id,form...

NPOI從資料庫中匯出到Excel

一,如何把資料庫的資料匯入到excel?1 可以使用多種方式,但是較好的一種是使用npoi。2 npoi的缺陷 只能在office2003中使用,office2007無法使用npoi,同時對於wps也不能使用。3 使用是要引入npoi的dll外部檔案,下面的 使用了簡單三層的思想。二,把資料庫中的資...