| Const SQLDMODataFile_CommaDelimitedChar = 1
Const SQLDMODataFile_TabDelimitedChar = 2
Const SQLDMODataFile_SpecialDelimitedChar = 3
TargetFile = "c:\tmp\社員マスタ.csv"
' オブジェクト作成
Set objServer = CreateObject("SQLDMO.SQLServer")
Set objBcp = CreateObject("SQLDMO.BulkCopy")
' BCP パラメータセット
objBcp.DataFileType = SQLDMODataFile_CommaDelimitedChar
' フィールド区切り文字と行終端文字を変更したい場合は以下
' objBcp.DataFileType = SQLDMODataFile_SpecialDelimitedChar
' objBcp.ColumnDelimiter = "\"
' objBcp.RowDelimiter = vbLf
objBcp.DataFilePath = TargetFile
' 接続
' 以下は別名。正確には、PC名\インスタンス名
Call objServer.Connect( "lbox", "sa", "password" )
' 対象オブジェクト
Set objDatabase = objServer.Databases("lightbox")
' VIEW 作成
Set objView = CreateObject("SQLDMO.View")
Set TypeLib = CreateObject("Scriptlet.TypeLib")
strGuid =Replace(TypeLib.Guid,"{", "" )
strGuid =Replace(strGuid,"}", "" )
strGuid =Replace(strGuid,"-", "" )
objView.Name = "TEMP_" & strGuid
objView.Text = "create VIEW " & objView.Name & " As select * from [社員マスタ] where 性別 = 0"
objDatabase.Views.Add(objView)
' 作成
nRow = objView.ExportData( objBcp )
' VIEW 削除
objView.Remove()
' 切断
Call objServer.DisConnect()
Wscript.Echo nRow & " 行のデータが出力されました"
| |