MS-SQL使用xp_cmdshellコマンドexcelへのデータのエクスポート


exec master..xp_cmdshell 'bcp "select c.Category_Title as   ,p.Category_Title as      from ltblGameStore..tbl_Category as c left join ltblGameStore..tbl_Category as p on c.Category_ParentId = p.Category_Id" queryout D:\test\Temp.xls  -c -q -S"192.168.100.18" -U"sa" -P"A_123"'

データベース使用:master
クエリのsql文のテーブル名を書くには:データベース名..テーブル名
エクスポートしたファイルをフォルダの下に置き、このフォルダにEveryone権限を与えます.