[MSSQL]如何將輸出資料存入sql server

有關資料庫的討論, 都可以在這發表哦~~
回覆文章
頭像
tim
文章: 1380
註冊時間: 2008年 11月 26日, 00:49

[MSSQL]如何將輸出資料存入sql server

文章 tim »

How To Get Output Into SQL Server Table
http://www.databasejournal.com/features ... hp/3386661

有時需要將系統的輸出資料導入 table 中, 應該如何進行, 請參考上面的文章, 相關範例如下,

Getting Output from a Stored Procedure into a Table

set nocount on
create table #sp_who (
spidsmallint,
ecidsmallint,
statusnchar(30),
loginamenchar(128),
hostnamenchar(128),
blkchar(5),
dbnamenchar(128),
cmdnchar(16))
insert into #sp_who execute sp_who
select * from #sp_who
drop table #sp_who


Getting the Content of an OS File into a Table

create table #errorlog(line varchar(2000))
insert into #errorlog
execute xp_cmdshell 'type "C:Program FilesMicrosoft SQL ServerMSSQLLOGERRORLOG" '
select line from #errorlog
drop table #errorlog


Getting Multiple Record Sets into a Table

create table #errorlog(line varchar(2000))
execute master.dbo.xp_cmdshell 'osql -SYourSQLMachine
-E -Q"execute sp_spaceused" -o"c:tempsp_out.txt" -s"" '
insert into #errorlog
execute master.dbo.xp_cmdshell 'type "c:tempsp_out.txt" '
select line from #errorlog
drop table #errorlog


Output From an Executable Into a Table

create table #ipconfig(line varchar(2000))
insert into #ipconfig
execute xp_cmdshell 'ipconfig.exe'
select line from #ipconfig
drop table #ipconfig
多多留言, 整理文章, 把經驗累積下來.....
回覆文章