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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Specify delimiter and quote on SQL Export Statement 1

Status
Not open for further replies.

Swi

Programmer
Feb 4, 2002
1,963
0
36
US
Is there any way to specify the delimeter and qualifying quotes on an export from an SQL command?

Code:
    If fso.FileExists(FilePath & "XXXX_" & Format(Date, "MM-DD-YYYY") & ".txt") Then fso.DeleteFile FilePath & "XXXX_" & Format(Date, "MM-DD-YYYY") & ".txt", True
    conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source='" & App.Path & "\" & MDBFileName & "'"
    conn.Execute "SELECT * INTO [Text;Database=" _
                     & FilePath _
                     & "].[XXXX_" & Format(Date, "MM-DD-YYYY") & ".txt] " _
                     & "FROM [Final]", , _
                       adCmdText Or adExecuteNoRecords

Thanks.

Swi
 
Ok, thanks. Will look into that. What are your thoughts on this?

Code:
        conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source='" & App.Path & "\" & MDBFileName & "'"
        rstxt.Open "SELECT * FROM [Final]", conn
        Set OutStream = fso.OpenTextFile(FilePath & "Test_" & Format(Date, "MM-DD-YYYY") & ".txt", ForWriting, True)
        Dim HeaderTxtFnl As String
        HeaderTxtFnl = ""
        Dim z As Integer
        For z = 0 To rstxt.Fields.Count - 1
            HeaderTxtFnl = HeaderTxtFnl & rstxt.Fields(z).Name & vbTab
        Next
        OutStream.WriteLine Left(HeaderTxtFnl, Len(HeaderTxtFnl) - 1)
        OutStream.Write rstxt.GetString(adClipString, , vbTab, vbCrLf, "")
        OutStream.Close
        rstxt.Close
        conn.Close
        Set conn = Nothing
        Set rstxt = Nothing
        Set OutStream = Nothing

Swi
 
Well, it is a viable approach - albeit a little clunky (and doesn't appear to meet your requirement to specify qualifying quotes)
 
If you have successfully run the command from your original post, you should find a schema.ini has been created for you in FilePath folder.

The vague outline of what you need to do is then:

All you need to do is make sure that you append an entry for

[XXXX_" & Format(Date, "MM-DD-YYYY") & ".txt]

with settings like the following

Format=Delimited(*)
TextDelimiter='


And that's it. Your CSV will then have (in this case) as * delimiting each column, and text will be qualified by a single quote
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top