Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Transfer query results to a file

Status
Not open for further replies.

developer155

Programmer
Jan 21, 2004
512
US
What is the way to transfer query results (held in a Object variable) into a file on a network?

thanks!
 
Will something like this work:
Code:
Function Main()
	On Error Resume Next

	Dim strRecord
	Dim objFso
	Dim objStream
	Dim objResults

        'path to your output file, change it to a UNC path if you need to
	const OUTPUT_FILE = "D:\Shared\FileDump\Logs1.txt"
	const FSOFORWRITING = 2

	Set objFso = CreateObject("Scripting.FileSystemObject")
	Set objResults = DTSGlobalVariables("GlobalVarialbeNameThatHoldsTheResultSet").Value
	Set objStream = objFso.CreateTextFile(OUTPUT_FILE, FSOFORWRITING, 2)

	While Not objResults.EOF
		
		strRecord = objResults("field1") & "|" & objResults("field2") & "|" & objResults("field3") & "|" & objResults("field4")
		
		objStream.WriteLine(strRecord)

		objResults.MoveNext

	Wend

	objResults.Close
	objStream.Close
	
	Set objStream = Nothing
	Set objFso = Nothing
	Set objResults = Nothing
	
	If Err.Count = 0 Then

		Main = DTSTaskExecResult_Success

	Else

		Main = DTSTaskExecResult_Failure

	End If
	
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top