在线播放亚洲第一字幕,大鸡巴操死我了视频网站,欧美日韩中文字,久久久999婷婷欧美一区

以文本方式查看主題

-  昂捷論壇  (http://www.yzsenyi.com/bbs/index.asp)
--  □-系統(tǒng)配置管理類  (http://www.yzsenyi.com/bbs/list.asp?boardid=34)
----  [原創(chuàng)]如何將sql語句執(zhí)行結(jié)果變成文本文檔  (http://www.yzsenyi.com/bbs/dispbbs.asp?boardid=34&id=9339)

--  作者:prcak47
--  發(fā)布時(shí)間:2016/1/23 14:54:14
--  [原創(chuàng)]如何將sql語句執(zhí)行結(jié)果變成文本文檔

如何將sql語句執(zhí)行結(jié)果變成文本文檔

 

可以在系統(tǒng)里面運(yùn)行dos命令,或者用bat批處理,將sql的執(zhí)行結(jié)果變成文本文檔

具體使用語句sqlcmd命令,命令格式如下:

sqlcmd
[{ { -U login_id [ -P password ] } | –E trusted connection }]
[ -N encrypt connection ][ -C trust the server certificate ]
[ -z new password ] [ -Z new password and exit]
[ -S [protocol:]server[\\instance_name][,port] ] [ -H wksta_name ] [ -d db_name ]
[ -l login time_out ] [ -A dedicated admin connection]
[ -i input_file ] [ -o output_file ]
[ -f < codepage > | i: < codepage > [ < , o: < codepage > ] ]
[ -u unicode output] [ -r [ 0 | 1 ] msgs to stderr ]
[ -R use client regional settings]
[ -q "cmdline query" ] [ -Q "cmdline query" and exit]
[ -e echo input ] [ -t query time_out ]
[ -I enable Quoted Identifiers ]
[ -v var = "value"...] [ -x disable variable substitution ]
[ -h headers ][ -s col_separator ] [ -w column_width ]
[ -W remove trailing spaces ]
[ -k [ 1 | 2 ] remove[replace] control characters ]
[ -y display_width ] [-Y display_width ]
[ -b on error batch abort] [ -V severitylevel ] [ -m error_level ]
[ -a packet_size ][ -c cmd_end ]
[ -L [ c ] list servers[clean output] ]
[ -p [ 1 ] print statistics[colon format]]
[ -X [ 1 ] ] disable commands, startup script, enviroment variables [and exit]
[ -? show syntax summary]

-U login_id
是用戶登錄 ID。

-P password
用戶指定的密碼。

-E trusted connection
使用信任連接而不是用戶名和密碼登錄

-N encrypt connection
此開關(guān)供客戶端用于請求加密連接

-C trust the server certificate
該開關(guān)供客戶端用于將其配置為隱式表示信任服務(wù)器證書且無需驗(yàn)證。

-z new password
更改密碼:
-Z new password and exit
更改密碼并退出:

-S [protocol:]server[\\instance_name][,port]
指定要連接的 SQL Server 實(shí)例。

-H wksta_name
工作站的名稱。

-d db_name
啟動 sqlcmd 時(shí)發(fā)出一個(gè) USE db_name 語句。

-l logintime_out
指定在您嘗試連接到服務(wù)器時(shí) OLE DB 訪問接口的 sqlcmd 登錄超時(shí)時(shí)間(以秒計(jì))。

-A dedicated admin connection
使用專用管理員連接 (DAC) 登錄到 SQL Server。

-i input_file[,input_file2...]
標(biāo)識包含一批 SQL 語句或存儲過程的文件。

-o output_file
標(biāo)識從 sqlcmd 接收輸出的文件。

-u unicode output
指定無論 input_file 為何種格式,output_file 都以 Unicode 格式進(jìn)行存儲。

-r[ 0 | 1] msgs to stderr
將錯誤消息輸出重定向到屏幕 (stderr)。

-R use client regional settings
促使 sqlcmd 根據(jù)客戶端的區(qū)域設(shè)置本地化從 SQL Server 中檢索到的數(shù)字、貨幣、日期和時(shí)間列。

-q" cmdline query "
啟動 sqlcmd 時(shí)執(zhí)行查詢,但是在查詢結(jié)束運(yùn)行時(shí)不退出 sqlcmd。

-Q"cmdline query " and exit
在 sqlcmd 啟動時(shí)執(zhí)行查詢,隨后立即退出 sqlcmd。

-e echo input
將輸入腳本寫入標(biāo)準(zhǔn)輸出設(shè)備 (stdout)。

-I enable Quoted Identifiers
將 SET QUOTED_IDENTIFIER 連接選項(xiàng)設(shè)置為 ON。

-t querytime_out
指定命令(或 SQL 語句)超時(shí)的時(shí)間。

-x disable variable substitution
導(dǎo)致 sqlcmd 忽略腳本變量。

-h headers
指定要在列標(biāo)題之間輸出的行數(shù)。默認(rèn)為每一組查詢結(jié)果輸出一次標(biāo)題。使用 -1 指定不能輸出標(biāo)題。

-s col_separator
指定列分隔符字符。默認(rèn)為空格。

-w column_width
指定用于輸出的屏幕寬度。

-W remove trailing spaces
此選項(xiàng)刪除列的尾隨空格。

-k [ 1 | 2 ] remove[replace] control characters
刪除輸出中的所有控制字符,例如制表符和換行符。

-y display_width
設(shè)置 sqlcmd 腳本變量 SQLCMDMAXFIXEDTYPEWIDTH。

-Y display_width
設(shè)置 sqlcmd 腳本變量 SQLCMDMAXVARTYPEWIDTH。

-b on error batch abort
指定發(fā)生錯誤時(shí),sqlcmd 退出并返回一個(gè) DOS ERRORLEVEL 值。

-V severitylevel
控制用于設(shè)置 ERRORLEVEL 變量的安全級別。

-m error_level
控制將哪些錯誤消息發(fā)送到 stdout。

-a packet_size
需要不同大小的數(shù)據(jù)包。

-c cmd_end
指定批處理終止符。
-L [ c ] list servers[clean output]
列出在本地配置的服務(wù)器和在網(wǎng)絡(luò)上廣播的服務(wù)器的名稱。

-p [ 1 ] print statistics[colon format]
輸出每個(gè)結(jié)果集的性能統(tǒng)計(jì)信息。

-X [ 1 ] disable commands, startup script, enviroment variables [and exit]
從批處理文件執(zhí)行 sqlcmd 時(shí),將禁用可能危及系統(tǒng)安全的命令。

 

 

具體實(shí)現(xiàn)如下:

首先做一個(gè)文本文檔sql.txt,放入需要執(zhí)行的語句

set nocount on

select c_userno,c_name,c_type,c_status,c_phone from tb_user

 

再做一個(gè)批處理文件sql.bat

sqlcmd -S 127.0.0.1 -d enjoy_shq -U sa -P 123456 -i D:\\sql.txt -o D:\\result.txt -u -h -1

 

 

執(zhí)行bat文件,就可以將sql執(zhí)行結(jié)果輸出到文本文檔result.txt

 

具體參數(shù)解釋:

-S 127.0.0.1 數(shù)據(jù)庫地址

-d enjoy_shq 數(shù)據(jù)庫名稱

-U sa 登錄用戶名

-P ****** 登錄密碼

-i D:\\sql.txt 執(zhí)行腳本

-o D:\\result.txt 輸出文件名

-u 以Unicode 格式進(jìn)行存儲

-h -1 不輸出標(biāo)題

 

語句中set nocount on 控制是否輸出執(zhí)行結(jié)果的行數(shù)

 

如果想要帶參數(shù)

語句可以寫為


set nocount on

select c_userno,c_name,c_type,c_status,c_phone from tb_user
where c_userno = $(userno)

 

執(zhí)行的批處理寫為

sqlcmd -S 127.0.0.1 -d enjoy_shq -U sa -P 123456 -i D:\\sql.txt -o D:\\result.txt -u -h -1 -v userno = "0000"

 

 

 

 

https://msdn.microsoft.com/zh-cn/library/ms162773.aspx

 

 

 

 

 

[此貼子已經(jīng)被作者于2016/1/23 15:26:22編輯過]

--  作者:prcak47
--  發(fā)布時(shí)間:2016/2/19 17:42:40
--  

以上語句在sql2008測試通過,sql2000的話,可以在cmd下運(yùn)行下面語句

 

bcp "SELECT c_userno,c_name,c_type,c_status,c_phone FROM enjoy_shq.dbo.tb_user" queryout D:\\result.txt -c -t , -S 127.0.0.1 -U sa -P 123456"

 


宁波市| 微山县| 凤城市| 太仆寺旗| 宾阳县| 星座| 丰宁| 凤阳县| 韶关市| 丹寨县| 杭锦旗| 灵寿县| 陇西县| 山阳县| 淮安市| 陆河县| 长岛县| 自治县| 聂拉木县| 武鸣县| 根河市| 南通市| 锡林郭勒盟| 南陵县| 岳普湖县| 舞阳县| 张家口市| 涿鹿县| 托里县| 平邑县| 郯城县| 金昌市| 聂拉木县| 阿克| 从化市| 日照市| 革吉县| 灯塔市| 吴川市| 昭平县| 兴安县|