[dba-SQLServer]Exporting tables to text

Elizabeth ecarey at myway.com
Fri Apr 25 09:15:37 CDT 2003


Sheesh, sorry.  I hadn't actually run through it in an ADP.

Well, you could always manually create your file in code.  I had to do this for a file that was loaded into DB2.  The load card expected some header information in the file, so it was just as easy to create the text file manually in code.

The code I have has lots of extra stuff in it that you probably don't need, so I'll give you the jist of it (this is DAO, just create your recordset in ADO..):


Public Sub CreateFile()
Dim rst As DAO.Recordset
Dim strSQL As String
Dim db As DAO.Database
Dim strLine As String
On Error GoTo CreateFileError

Set db = CurrentDb
strSQL = "SELECT * from tbltmpDataForFile"
Set rst = db.OpenRecordset(strSQL, dbOpenSnapshot)
Open "c:\TESTFILE.txt" For Output As #1

With rst
    Do While Not .EOF
        If (!earningscode = "602" Or !earningscode = "603") And _
                Nz(!transactionamount) = 0 Then
            .MoveNext
        Else
            strLine = "T,"
            strLine = strLine & "0" & !ISESyscd & ","
            strLine = strLine & "0" & !transactiontype & ","
            strLine = strLine & !earningscode & ","        
            strLine = strLine & strAmount & ","
            strLine = strLine & !LivingDedCode & ","          
            strLine = strLine & strAmount
            Print #1, strLine
            .MoveNext
        End If
    Loop
End With
rst.Close
Set rst = Nothing
Set db = Nothing

Elizabeth



--- On Thu 04/24, David Emerson < davide at dalyn.co.nz > wrote:From: David Emerson [mailto: davide at dalyn.co.nz]To: dba-sqlserver at databaseadvisors.comDate: Fri, 25 Apr 2003 10:17:09 +1200Subject: RE: [dba-SQLServer]Exporting tables to textThanks for the reply. Unfortunately I am using an adp which doesn't allow 
the saving of secifications.



_______________________________________________
No banners. No pop-ups. No kidding.
Introducing My Way - http://www.myway.com


More information about the dba-SQLServer mailing list